├── .php_cs ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── AdsenseBuilder.php ├── Facades │ └── AdsenseFacade.php ├── Providers │ └── AdsenseServiceProvider.php └── resources │ ├── config │ └── adsense.php │ └── views │ ├── ads.blade.php │ └── javascript.blade.php └── tests ├── AdsenseTest.php ├── TestCase.php └── stubs └── views ├── ads.blade.php └── javascript.blade.php /.php_cs: -------------------------------------------------------------------------------- 1 | 13 | 14 | @copyright Copyright (c) 2021 Martin Butt 15 | @license MIT 16 | 17 | Copyright (c) 2016 Galen Han 18 | Copyright (c) 2019 Crypto Technology srl 19 | Copyright (c) 2021 Martin Butt 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy of 22 | this software and associated documentation files (the "Software"), to deal in 23 | the Software without restriction, including without limitation the rights to 24 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 25 | the Software, and to permit persons to whom the Software is furnished to do so, 26 | subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all 29 | copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 33 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 34 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 35 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 36 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 | EOF; 38 | 39 | $finder = Finder::create() 40 | ->in(__DIR__) 41 | ->ignoreDotFiles(true) 42 | ->ignoreVCS(true) 43 | ->ignoreUnreadableDirs() 44 | ->files() 45 | ->name('*.php') 46 | //->exclude(['index.php']) //files 47 | ->exclude(['.idea', 'tests', 'vendor']); //dirs 48 | 49 | $config = Config::create() 50 | ->setUsingCache(true) 51 | ->setCacheFile(__DIR__.'/.php_cs.cache') 52 | ->setFinder($finder) 53 | ->setRiskyAllowed(true) 54 | ->setRules([ 55 | '@Symfony' => true, 56 | '@PSR2' => true, 57 | 'align_multiline_comment' => ['comment_type' => 'phpdocs_only'], 58 | 'array_indentation' => true, 59 | 'array_syntax' => ['syntax' => 'short'], 60 | 'combine_consecutive_issets' => true, 61 | 'combine_consecutive_unsets' => true, 62 | 'declare_strict_types' => true, 63 | 'dir_constant' => true, 64 | 'header_comment' => ['comment_type' => 'PHPDoc', 'header' => $header, 'location' => 'after_open', 'separate' => 'both'], 65 | 'is_null' => true, 66 | 'linebreak_after_opening_tag' => true, 67 | 'logical_operators' => true, 68 | 'mb_str_functions' => true, 69 | 'multiline_comment_opening_closing' => true, 70 | 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], 71 | 'native_constant_invocation' => true, 72 | 'native_function_invocation' => true, 73 | 'no_php4_constructor' => true, 74 | 'no_short_echo_tag' => true, 75 | 'no_superfluous_elseif' => true, 76 | 'no_superfluous_phpdoc_tags' => false, 77 | 'no_unneeded_curly_braces' => true, 78 | 'no_unreachable_default_argument_value' => true, 79 | 'no_unset_on_property' => true, 80 | 'no_useless_else' => true, 81 | 'no_useless_return' => true, 82 | 'not_operator_with_space' => true, 83 | 'not_operator_with_successor_space' => true, 84 | 'ordered_imports' => ['sortAlgorithm' => 'alpha'], 85 | 'php_unit_method_casing' => true, 86 | 'php_unit_strict' => true, 87 | 'php_unit_test_annotation' => ['style' => 'prefix'], // or 'annotation' 88 | 'phpdoc_add_missing_param_annotation' => true, //['only_untyped' => false], 89 | 'phpdoc_annotation_without_dot' => false, 90 | 'phpdoc_no_empty_return' => false, 91 | 'phpdoc_order' => true, 92 | 'phpdoc_to_comment' => false, 93 | 'phpdoc_trim_consecutive_blank_line_separation' => true, 94 | 'phpdoc_types_order' => ['sort_algorithm' => 'none'], 95 | 'pow_to_exponentiation' => true, 96 | 'psr4' => true, 97 | 'random_api_migration' => true, 98 | 'single_blank_line_at_eof' => true, 99 | 'strict_comparison' => true, 100 | 'strict_param' => true, 101 | 'ternary_to_null_coalescing' => true, 102 | 'whitespace_after_comma_in_array' => true, 103 | ]); 104 | 105 | return $config; 106 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | 9 | ## [1.3] - 2021-04-17 10 | ### Added 11 | - Added Laravel 7.x support 12 | 13 | ## [1.2] - 2019-12-20 14 | ### Added 15 | - Added new tests 16 | 17 | ### Fixed 18 | - Fixed error on binding class 19 | - Fixed some PhpDoc 20 | 21 | ## [1.1] - 2019-12-15 22 | ### Fixed 23 | - Fixed missing of publishing views 24 | 25 | ## [1.0] - 2019-12-14 26 | ### Added 27 | - Writed tests 28 | - Added CD & CI automations 29 | 30 | ### Changed 31 | - Support for Laravel 6.x 32 | 33 | ## [0.1.5] - 2017-09-01 34 | ### Added 35 | - Support for Laravel 5.5 36 | 37 | ## [0.1.4] - 2017-02-04 38 | ### Added 39 | - Support for Laravel 5.4 40 | 41 | ## [0.1.3] - 2016-11-30 42 | ### Added 43 | - Support for Laravel 5.3 44 | 45 | ### Fixed 46 | - Fix showing Ads Banner with fixed style 47 | 48 | ### Changed 49 | - Use blade syntax for ad.blade.php 50 | 51 | ## [0.1.2] - 2016-01-03 52 | ### Added 53 | - Support for Laravel 5.2 54 | 55 | ## [0.1.1] - 2015-07-01 56 | ### Removed 57 | - Remove test function 58 | 59 | ## [0.1] - 2015-07-01 60 | ### Added 61 | - Initial release 62 | 63 | [Unreleased]: https://github.com/martinbutt/laravel-adsense/compare/v1.3...HEAD 64 | [1.3]: https://github.com/martinbutt/laravel-adsense/compare/v1.2...v1.3 65 | [1.2]: https://github.com/crypto-technology/laravel-adsense/compare/v1.1...v1.2 66 | [1.1]: https://github.com/crypto-technology/laravel-adsense/compare/v1.0...v1.1 67 | [1.0]: https://github.com/crypto-technology/laravel-adsense/compare/v0.1.5...v1.0 68 | [0.1.5]: https://github.com/crypto-technology/laravel-adsense/compare/v0.1.4...v0.1.5 69 | [0.1.4]: https://github.com/crypto-technology/laravel-adsense/compare/v0.1.3...v0.1.4 70 | [0.1.3]: https://github.com/crypto-technology/laravel-adsense/compare/v0.1.2...v0.1.3 71 | [0.1.2]: https://github.com/crypto-technology/laravel-adsense/compare/v0.1.1...v0.1.2 72 | [0.1.1]: https://github.com/crypto-technology/laravel-adsense/compare/v0.1...v0.1.1 73 | [0.1]: https://github.com/crypto-technology/laravel-adsense/releases/tag/v0.1 74 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Galen Han 4 | Copyright (c) 2019 Crypto Technology srl 5 | Copyright (c) 2021 Martin Butt 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google Adsense Ads for Laravel 6.x, 7.x and 8.x 2 | 3 | [![Latest Version][ico-version]][link-packagist] 4 | [![Total Downloads][ico-downloads]][link-downloads] 5 | [![Build Status][ico-travis]][link-travis] 6 | [![StyleCI][ico-styleci]][link-styleci] 7 | [![Scrutinizer][ico-scrutinizer]][link-scrutinizer] 8 | [![Code Coverage][ico-coverage]][link-coverage] 9 | [![License][ico-license]][link-license] 10 | 11 | Package for easily including Google Adsense Ad units in [Laravel 6.x, 7.x and 8.x][link-laravel] and [Lumen][link-lumen]. For use with Laravel 5.x use original [Mastergalen/Adsense-Ads package][link-mastergalen-adsense]. 12 | 13 | ## Installation 14 | 15 | ### 1 - Dependency 16 | 17 | In your project root run 18 | 19 | The first step is using [Composer][link-composer] to install the package and automatically update your `composer.json` file, you can do this by running: 20 | 21 | ```shell 22 | composer require martinbutt/laravel-adsense 23 | ``` 24 | 25 | ### 2 - Set up config file 26 | 27 | Run `php artisan config:publish martinbutt/laravel-adsense`. 28 | 29 | Edit the generated config file in `/config/adsense.php` to add your ad units 30 | 31 | ```php 32 | return [ 33 | 'client_id' => 'YOUR_CLIENT_ID', //Your Adsense client ID e.g. ca-pub-9508939161510421 34 | 'ads' => [ 35 | 'responsive' => [ 36 | 'ad_slot' => 1111111111, 37 | 'ad_format' => 'fluid', 38 | 'ad_full_width_responsive' => true, 39 | 'ad_style' => 'display:inline-block' 40 | ], 41 | 'rectangle' => [ 42 | 'ad_slot' => 2222222222, 43 | 'ad_style' => 'display:inline-block;width:300px;height:250px', 44 | 'ad_full_width_responsive' => false, 45 | 'ad_format' => 'auto' 46 | ] 47 | ] 48 | ]; 49 | ``` 50 | 51 | ### 3 - Register the provider with Laravel 52 | 53 | You need to update your application configuration in order to register the package so it can be loaded by Laravel, just update your `config/app.php` file adding the following code at the end of your `'providers'` section: 54 | 55 | > `config/app.php` 56 | 57 | ```php 58 | [ 63 | MartinButt\Laravel\Adsense\Providers\AdsenseServiceProvider::class, 64 | // ... 65 | ], 66 | // ... 67 | ]; 68 | ``` 69 | 70 | #### Lumen 71 | 72 | Go to `bootstrap/app.php` file and add this line: 73 | 74 | ```php 75 | register(MartinButt\Laravel\Adsense\Providers\AdsenseServiceProvider::class); 85 | 86 | // ... 87 | 88 | return $app; 89 | ``` 90 | 91 | ### 4 - Register the alias with Laravel 92 | 93 | > Note: facades are not supported in Lumen. 94 | 95 | You may get access to the Google Adsense Ads services using following facades: 96 | 97 | - `MartinButt\Laravel\Adsense\Facades\AdsenseFacade` 98 | 99 | You can setup a short-version aliases for these facades in your `config/app.php` file. For example: 100 | 101 | ```php 102 | [ 107 | 'Adsense' => MartinButt\Laravel\Adsense\Facades\AdsenseFacade::class, 108 | // ... 109 | ], 110 | // ... 111 | ]; 112 | ``` 113 | 114 | ### 5 - Configuration 115 | 116 | #### Publish config 117 | 118 | In your terminal type 119 | 120 | ```shell 121 | php artisan vendor:publish 122 | ``` 123 | 124 | or 125 | 126 | ```shell 127 | php artisan vendor:publish --provider="MartinButt\Laravel\Adsense\Providers\AdsenseServiceProvider" 128 | ``` 129 | 130 | > Lumen does not support this command, for it you should copy the file `src/resources/config/adsense.php` to `config/adsense.php` of your project. 131 | 132 | In `adsense.php` configuration file you can determine the properties of the default values and some behaviors. 133 | 134 | ## Usage 135 | Add `{!! Adsense::javascript() !!}` in your `
` tag. 136 | 137 | To show ads, add `{!! Adsense::ads('ads_unit') !!}`, where `ads_unit` is one of your ads units in your config file (for example `{!! Adsense::ads('responsive') !!}`). 138 | 139 | Use `{!! Adsense::ads('ads_unit') !!}` every time you want to show an ad. 140 | 141 | ## Changelog 142 | 143 | Please see the [CHANGELOG.md][link-changelog] file for more information on what has changed recently. 144 | 145 | ## Credits 146 | 147 | - [Martin Butt][link-author] 148 | - [Crypto Technology srl][link-coauthor1] 149 | - [Luca Bognolo][link-coauthor2] 150 | - [All Contributors][link-contributors] 151 | 152 | ## License 153 | 154 | The Google Adsense Ads is open-sourced software licensed under the [MIT license][link-mit-license]. 155 | Please see the [LICENSE.md][link-license] file for more information. 156 | 157 | [ico-version]: https://img.shields.io/packagist/v/martinbutt/laravel-adsense.svg?style=flat-square 158 | [ico-downloads]: https://img.shields.io/packagist/dt/martinbutt/laravel-adsense.svg?style=flat-square 159 | [ico-travis]: https://img.shields.io/travis/martinbutt/laravel-adsense/master.svg?style=flat-square 160 | [ico-styleci]: https://styleci.io/repos/359045604/shield?style=flat-square 161 | [ico-scrutinizer]: https://scrutinizer-ci.com/g/martinbutt/laravel-adsense/badges/quality-score.png?b=master 162 | [ico-coverage]: https://scrutinizer-ci.com/g/martinbutt/laravel-adsense/badges/coverage.png 163 | [ico-license]: https://img.shields.io/packagist/l/martinbutt/laravel-adsense?style=flat-square 164 | 165 | [link-packagist]: https://packagist.org/packages/martinbutt/laravel-adsense 166 | [link-downloads]: https://packagist.org/packages/martinbutt/laravel-adsense 167 | [link-travis]: https://travis-ci.com/martinbutt/laravel-adsense 168 | [link-styleci]: https://styleci.io/repos/359045604 169 | [link-scrutinizer]: https://scrutinizer-ci.com/g/martinbutt/laravel-adsense/?branch=master 170 | [link-coverage]: https://scrutinizer-ci.com/g/martinbutt/laravel-adsense 171 | [link-laravel]: https://laravel.com 172 | [link-lumen]: https://lumen.laravel.com 173 | [link-mastergalen-adsense]: https://github.com/Mastergalen/Adsense-Ads 174 | [link-composer]: https://getcomposer.org 175 | [link-license]: LICENSE.md 176 | [link-changelog]: CHANGELOG.md 177 | [link-author]: https://www.martinbutt.com 178 | [link-coauthor1]: https://cryptotech.srl 179 | [link-coauthor2]: https://bogny.eu 180 | [link-contributors]: ../../contributors 181 | [link-mit-license]: https://opensource.org/licenses/MIT 182 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "martinbutt/laravel-adsense", 3 | "description": "Display Adsense ads easily in Laravel 6.x, 7.x and 8.x", 4 | "keywords": [ "laravel", "adsense", "ads" ], 5 | "type": "library", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Martin Butt", 10 | "homepage": "https://www.martinbutt.com", 11 | "role": "Developer" 12 | }, 13 | { 14 | "name": "Crypto Technology srl", 15 | "email": "admin@cryptotech.srl", 16 | "homepage": "https://cryptotech.srl", 17 | "role": "Developer" 18 | } 19 | ], 20 | "support": { 21 | "issues": "https://github.com/martinbutt/laravel-adsense/issues", 22 | "source": "https://github.com/martinbutt/laravel-adsense/" 23 | }, 24 | "require": { 25 | "php": "^7.2||^8.0", 26 | "illuminate/view": "^6.0||^7.0||^8.0" 27 | }, 28 | "require-dev": { 29 | "friendsofphp/php-cs-fixer": "^2.16", 30 | "orchestra/testbench": "^4.0", 31 | "phpunit/phpunit": "^8.0" 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "MartinButt\\Laravel\\Adsense\\": "src" 36 | } 37 | }, 38 | "autoload-dev": { 39 | "psr-4": { 40 | "MartinButt\\Laravel\\Adsense\\Tests\\": "tests" 41 | } 42 | }, 43 | "extra": { 44 | "laravel": { 45 | "providers": [ 46 | "MartinButt\\Laravel\\Adsense\\Providers\\AdsenseServiceProvider" 47 | ], 48 | "aliases": { 49 | "Adsense": "MartinButt\\Laravel\\Adsense\\Facades\\AdsenseFacade" 50 | } 51 | } 52 | }, 53 | "scripts": { 54 | "test": "composer dump-autoload && phpunit --configuration phpunit.xml", 55 | "php-cs-fixer": "php-cs-fixer fix . --verbose --show-progress=estimating --dry-run --diff" 56 | }, 57 | "config": { 58 | "optimize-autoloader": true, 59 | "preferred-install": "dist", 60 | "sort-packages": true 61 | }, 62 | "minimum-stability": "dev", 63 | "prefer-stable": true 64 | } 65 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 |