├── tests └── .gitkeep ├── .gitignore ├── .travis.yml ├── src └── Thujohn │ └── Share │ ├── ShareFacade.php │ ├── ShareServiceProvider.php │ └── Share.php ├── composer.json ├── phpunit.xml ├── LICENSE └── README.md /tests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | 7 | before_script: 8 | - curl -s http://getcomposer.org/installer | php 9 | - php composer.phar install --dev 10 | 11 | script: phpunit -------------------------------------------------------------------------------- /src/Thujohn/Share/ShareFacade.php: -------------------------------------------------------------------------------- 1 | =5.3.0", 14 | "illuminate/support": "4.x" 15 | }, 16 | "autoload": { 17 | "psr-0": { 18 | "Thujohn\\Share": "src/" 19 | } 20 | }, 21 | "minimum-stability": "dev" 22 | } 23 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Thujohn/Share/ShareServiceProvider.php: -------------------------------------------------------------------------------- 1 | package('thujohn/share'); 22 | } 23 | 24 | /** 25 | * Register the service provider. 26 | * 27 | * @return void 28 | */ 29 | public function register() 30 | { 31 | $this->app['share'] = $this->app->share(function($app) 32 | { 33 | return new Share; 34 | }); 35 | } 36 | 37 | /** 38 | * Get the services provided by the provider. 39 | * 40 | * @return array 41 | */ 42 | public function provides() 43 | { 44 | return array('share'); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) <2013> 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Share 2 | 3 | Share links with Laravel 4 4 | 5 | [![Build Status](https://travis-ci.org/thujohn/share-l4.png?branch=master)](https://travis-ci.org/thujohn/share-l4) 6 | 7 | 8 | ## Installation 9 | 10 | Add `thujohn/share` to `composer.json`. 11 | 12 | "thujohn/share": "dev-master" 13 | 14 | Run `composer update` to pull down the latest version of Share. 15 | 16 | Now open up `app/config/app.php` and add the service provider to your `providers` array. 17 | 18 | 'providers' => array( 19 | 'Thujohn\Share\ShareServiceProvider', 20 | ) 21 | 22 | Now add the alias. 23 | 24 | 'aliases' => array( 25 | 'Share' => 'Thujohn\Share\ShareFacade', 26 | ) 27 | 28 | 29 | ## Usage 30 | 31 | Get a link (example with Twitter) 32 | 33 | Route::get('/', function() 34 | { 35 | return Share::load('http://www.example.com', 'My example')->twitter(); 36 | }); 37 | 38 | Returns a string : 39 | 40 | https://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.example.com&text=Link+description 41 | 42 | 43 | Get many links 44 | 45 | Route::get('/', function() 46 | { 47 | return Share::load('http://www.example.com', 'Link description')->services('facebook', 'gplus', 'twitter'); 48 | }); 49 | 50 | Returns an array : 51 | 52 | {"facebook":"https:\/\/www.facebook.com\/sharer\/sharer.php?u=http%3A%2F%2Fwww.example.com&title=Link+description","gplus":"https:\/\/plus.google.com\/share?url=http%3A%2F%2Fwww.example.com","twitter":"https:\/\/twitter.com\/intent\/tweet?url=http%3A%2F%2Fwww.example.com&text=Link+description"} 53 | 54 | 55 | ## Services available 56 | - Delicious : delicious 57 | - Digg : digg 58 | - Evernote : evernote 59 | - Facebook : facebook 60 | - Gmail : gmail 61 | - Google Plus : gplus 62 | - LinkedIn : linkedin 63 | - Pinterest : pinterest 64 | - Reddit : reddit 65 | - Scoop.it : scoopit 66 | - Springpad : springpad 67 | - Tumblr : tumblr 68 | - Twitter : twitter 69 | - Viadeo : viadeo 70 | - vk.com : vk 71 | -------------------------------------------------------------------------------- /src/Thujohn/Share/Share.php: -------------------------------------------------------------------------------- 1 | link = urlencode($link); 10 | $this->text = urlencode($text); 11 | $this->media = urlencode($media); 12 | 13 | return $this; 14 | } 15 | 16 | public function services(){ 17 | $services = func_get_args(); 18 | 19 | $object = false; 20 | if (end($services) === true) 21 | { 22 | $object = true; 23 | array_pop($services); 24 | } 25 | 26 | $return = array(); 27 | 28 | if ($services){ 29 | foreach ($services as $service){ 30 | if (method_exists('Thujohn\Share\Share', $service)){ 31 | $return[$service] = $this->$service(); 32 | } 33 | } 34 | } 35 | 36 | if ($object) 37 | { 38 | return (object) $return; 39 | } 40 | 41 | return $return; 42 | } 43 | 44 | public function delicious(){ 45 | return 'https://delicious.com/post?url='.$this->link.(($this->text) ? '&title='.$this->text : ''); 46 | } 47 | 48 | public function digg(){ 49 | return 'http://www.digg.com/submit?url='.$this->link.(($this->text) ? '&title='.$this->text : ''); 50 | } 51 | 52 | public function evernote(){ 53 | return 'http://www.evernote.com/clip.action?url='.$this->link.(($this->text) ? '&title='.$this->text : ''); 54 | } 55 | 56 | public function facebook(){ 57 | return 'https://www.facebook.com/sharer/sharer.php?u='.$this->link.(($this->text) ? '&title='.$this->text : ''); 58 | } 59 | 60 | public function gmail(){ 61 | return 'https://mail.google.com/mail/?view=cm&fs=1&to&ui=2&tf=1&su='.$this->link.(($this->text) ? '&body='.$this->text : ''); 62 | } 63 | 64 | public function gplus(){ 65 | return 'https://plus.google.com/share?url='.$this->link; 66 | } 67 | 68 | public function linkedin(){ 69 | return 'http://www.linkedin.com/shareArticle?mini=true&url='.$this->link.(($this->text) ? '&title='.$this->text : ''); 70 | } 71 | 72 | public function pinterest(){ 73 | return 'http://pinterest.com/pin/create/button/?url='.$this->link.(($this->media) ? '&media='.$this->media : '').(($this->text) ? '&description='.$this->text : ''); 74 | } 75 | 76 | public function reddit(){ 77 | return 'http://www.reddit.com/submit?url='.$this->link.(($this->text) ? '&title='.$this->text : ''); 78 | } 79 | 80 | public function scoopit(){ 81 | return 'http://www.scoop.it/oexchange/share?url='.$this->link.(($this->text) ? '&title='.$this->text : ''); 82 | } 83 | 84 | public function springpad(){ 85 | return 'https://springpadit.com/s?type=lifemanagr.Bookmark&url='.$this->link.(($this->text) ? '&name='.$this->text : ''); 86 | } 87 | 88 | public function tumblr(){ 89 | return 'http://www.tumblr.com/share?v=3&u='.$this->link.(($this->text) ? '&t='.$this->text : ''); 90 | } 91 | 92 | public function twitter(){ 93 | return 'https://twitter.com/intent/tweet?url='.$this->link.(($this->text) ? '&text='.$this->text : ''); 94 | } 95 | 96 | public function viadeo(){ 97 | return 'http://www.viadeo.com/?url='.$this->link.(($this->text) ? '&title='.$this->text : ''); 98 | } 99 | 100 | public function vk(){ 101 | return 'http://vk.com/share.php?url='.$this->link.(($this->media) ? '&image='.$this->media : '').(($this->text) ? '&title='.$this->text : '').'&noparse=false'; 102 | } 103 | } 104 | --------------------------------------------------------------------------------