dev-master
9999999-devSimple Silverstripe CMS wrapper to post to Twitter and Facebook Page Wall as Page
The Requires
silverstripe twitter
Simple Silverstripe CMS wrapper to post to Twitter and Facebook Page Wall as Page
This is a simple social-media-sharer. It will use the API of the selected (currently, only Twitter yet) social media to post something. Follow the instructions in your settings to get things working, (*1)
github[at]casa-laguna[dot]net
silverstripe-newsmodule
:<?php public function onAfterWrite(){ parent::onAfterWrite(); $siteConfig = SiteConfig::current_site_config(); /** * This is related to another module of mine. * Check it at my repos: Silverstripe-Social. * It auto-tweets your new Newsitem. If the TwitterController exists ofcourse. * You can do a lot of different configs here, but I strongly suggest to include the "Tweeted" boolean in your $db declaration. * Otherwise, you might tweet everytime you change something, which can get quite annoying ;) */ if($this->Live && !$this->Tweeted && $siteConfig->TweetOnPost){ if(class_exists('TwitterController')){ TwitterController::postTweet($this->Title, $this->AbsoluteLink()); $this->Tweeted = true; $this->write(); } } }
For Facebook, I used this test-function in page.php and called it via mydomain.com/home/testFacebook, (*2)
<?php public function testFacebook(){ FacebookController::postFacebook('New Message, hooray!'); }
Please help me test!, (*3)
User posting needs to be logged in to Facebook at the moment the module tries to post., (*4)
If you don't have a github account, just download:
1. Click on the big "ZIP" button at the top.
2. Extract the zip to your site-root
3. Run in your browser - www.example.com/dev/build
to rebuild the database., (*5)
Other option is to clone the repo into your site-root:
1. In your site-root, do git clone https://github.com/Firesphere/silverstripe-social.git
.
2. Run in your browser - www.example.com/dev/build
to rebuild the database., (*6)
Although, I would like it if you forked and cloned, because if you do, you can help me by adding features and make pull-requests to improve this module!
1. Make a fork of this module.
2. In your site-root, do git clone https://{your username}@github.com/{your username}/silverstripe-social.git
.
3. Run in your browser - www.example.com/dev/build
to rebuild the database., (*7)
Note, forking is NOT REQUIRED, only handy if you want to help out., (*8)
After installation, setup your app with the desired social network. For twitter, go here: https://dev.twitter.com
Setting up your application, will give you a consumer key/secret combination. Set this in your siteconfig and you're good to go., (*9)
For Facebook, it requires a few extra steps, sadly.
Here goes:
* Create a new app at https://developers.facebook.com
* Under "Select how your app integrates with Facebook" Select Website with Facebook Login and set the URL tp http://yoursi.te/FacebookController/callback/
* Copy the AppID, Secret and API-key to the corresponding fields in the CMS
* Make sure you are admin of the corresponding page you want to publish to.
* Get the page-ID. This one is tricky, google it, because I don't have much space.
* Sign in and see what happens., (*10)
I have explicitly NOT included my own keys in this module, because it's not necessary, create your own is better for you ;) Any questions would preferably be asked via the issues-github-method., (*11)
Please, please, please, do not forget to include a boolean in your page/model which checks if the specific model/page has already been posted to facebook. If you forget, you'll end up in an infinite loop and a LOT of deleting useless links from facebook! Working example can be found in my newsmodule git repo., (*12)
If you have Facebook connected to twitter, don't post to facebook and twitter as well! Twitter will reject your message because it's a duplicate!, (*13)
Yes, I know. I'm sorry., (*14)
This module is published under BSD 2-clause license, although these are not in the actual classes, the license does apply:, (*15)
http://www.opensource.org/licenses/BSD-2-Clause, (*16)
Copyright (c) 2013, Simon "Sphere" Erkelens, (*17)
All rights reserved., (*18)
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:, (*19)
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE., (*20)
(I shouldn't scream, should I? This is copy-paste from BSD-2 license...), (*21)
Simple Silverstripe CMS wrapper to post to Twitter and Facebook Page Wall as Page
silverstripe twitter