├── .gitignore ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Facades └── Metadata.php ├── Handlers └── Metadata.php └── SEOServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Shea Lewis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This package has been abandoned and is no longer maintained. 2 | 3 | Caffeinated SEO 4 | =============== 5 | [![Laravel 5.3](https://img.shields.io/badge/Laravel-5.3-orange.svg?style=flat-square)](http://laravel.com) 6 | [![Source](http://img.shields.io/badge/source-caffeinated/SEO-blue.svg?style=flat-square)](https://github.com/caffeinated/SEO) 7 | [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://tldrlegal.com/license/mit-license) 8 | 9 | Caffeinated SEO aids in the management and generation of SEO metadata for your Laravel 5 application. 10 | 11 | Documentation 12 | ------------- 13 | You will find user friendly and up to date documentation in the wiki here: [Caffeinated SEO Wiki](https://github.com/caffeinated/SEO/wiki) 14 | 15 | Quick Installation 16 | ------------------ 17 | Begin by installing the package through Composer. 18 | 19 | ``` 20 | composer require caffeinated/seo 21 | ``` 22 | 23 | Once this operation is complete, simply add both the service provider and facade classes to your project's `config/app.php` file: 24 | 25 | #### Service Provider 26 | ```php 27 | Caffeinated\SEO\SEOServiceProvider::class, 28 | ``` 29 | 30 | #### Facade 31 | ```php 32 | 'SEOMeta' => Caffeinated\SEO\Facades\Metadata::class, 33 | ``` 34 | 35 | And that's it! With your coffee in reach, start building up your SEO! 36 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "caffeinated/seo", 3 | "description": "Laravel 5 SEO generator", 4 | "keywords": ["seo", "metadata", "robots", "sitemap", "laravel", "caffeinated"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Shea Lewis", 9 | "email": "shea.lewis89@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.6.4", 14 | "illuminate/support": "5.3.*", 15 | "illuminate/config": "5.3.*" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "Caffeinated\\SEO\\": "src" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Facades/Metadata.php: -------------------------------------------------------------------------------- 1 | request = $request; 52 | } 53 | 54 | /** 55 | * Set the metadata title. 56 | * 57 | * @param string $title 58 | * @return null 59 | */ 60 | public function setTitle($title) 61 | { 62 | $title = strip_tags($title); 63 | 64 | $this->title = $title; 65 | } 66 | 67 | /** 68 | * Set the metadata description. 69 | * 70 | * @param string $description 71 | * @return null 72 | */ 73 | public function setDescription($description) 74 | { 75 | $description = strip_tags($description); 76 | 77 | if (strlen($description) > $this->maxDescriptionLength) { 78 | $description = substr($description, 0, $this->maxDescriptionLength); 79 | } 80 | 81 | $this->description = $description; 82 | } 83 | 84 | /** 85 | * Set the metadata keywords. 86 | * 87 | * @param array|string $keywords 88 | * @return null 89 | */ 90 | public function setKeywords($keywords) 91 | { 92 | $this->keywords = implode(', ', (array) $keywords); 93 | } 94 | 95 | /** 96 | * Set the canonical URL. 97 | * 98 | * @param string $url 99 | * @return null 100 | */ 101 | public function setCanonical($url) 102 | { 103 | $this->canonical = $url; 104 | } 105 | 106 | /** 107 | * Set miscellaneous metadata. 108 | * 109 | * @param string $name 110 | * @param string $content 111 | * @return null 112 | */ 113 | public function set($name, $content) 114 | { 115 | $content = strip_tags($content); 116 | 117 | $this->miscellaneous[$name] = $content; 118 | } 119 | 120 | /** 121 | * Get the metadata title. 122 | * 123 | * @return string|null 124 | */ 125 | public function getTitle() 126 | { 127 | return $this->title ?: null; 128 | } 129 | 130 | /** 131 | * Get the metadata description. 132 | * 133 | * @return string|null 134 | */ 135 | public function getDescription() 136 | { 137 | return $this->description ?: null; 138 | } 139 | 140 | /** 141 | * Get the metadata keywords. 142 | * 143 | * @return string|null 144 | */ 145 | public function getKeywords() 146 | { 147 | return $this->keywords ?: null; 148 | } 149 | 150 | /** 151 | * Get miscellaneous metadata. 152 | * 153 | * @return array|null 154 | */ 155 | public function getMiscellaneous() 156 | { 157 | return $this->miscellaneous ?: null; 158 | } 159 | 160 | /** 161 | * Get the canonical URL. 162 | * 163 | * @return string 164 | */ 165 | public function getCanonical() 166 | { 167 | return $this->canonical ?: null; 168 | } 169 | 170 | /** 171 | * Reset all metadata. 172 | * 173 | * @return void 174 | */ 175 | public function reset() 176 | { 177 | $this->title = null; 178 | $this->description = null; 179 | $this->keywords = null; 180 | $this->miscellaneous = null; 181 | $this->canonical = null; 182 | } 183 | 184 | /** 185 | * Generate and render the HTML metadata tags. 186 | * 187 | * @return string 188 | */ 189 | public function generate() 190 | { 191 | $title = $this->getTitle(); 192 | $description = $this->getDescription(); 193 | $keywords = $this->getKeywords(); 194 | $miscellaneous = $this->getMiscellaneous(); 195 | $canonical = $this->getCanonical(); 196 | 197 | $html[] = ''.$title.''.PHP_EOL; 198 | 199 | if (! is_null($description)) { 200 | $html[] = ''; 201 | } 202 | 203 | if (! is_null($keywords)) { 204 | $html[] = ''; 205 | } 206 | 207 | if (! is_null($miscellaneous)) { 208 | foreach ($miscellaneous as $name => $content) { 209 | $html[] = ''; 210 | } 211 | } 212 | 213 | if (! is_null($canonical)) { 214 | $currentUrl = $this->request->fullUrl(); 215 | 216 | if ($canonical != $currentUrl) { 217 | $html[] = PHP_EOL.''; 218 | } 219 | } 220 | 221 | return implode(PHP_EOL, $html); 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /src/SEOServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton('caffeinated.seo.metadata', function($app) { 34 | return new Metadata($app['request']); 35 | }); 36 | } 37 | 38 | /** 39 | * Get the services provided by the provider. 40 | * 41 | * @return array 42 | */ 43 | public function provides() 44 | { 45 | return [ 46 | 'caffeinated.metadata' 47 | ]; 48 | } 49 | } 50 | --------------------------------------------------------------------------------