Saturday 16 August 2014

TYPO3 Neos:Multi Channel Publishing (Facebook)

In this Blog post I will try to explain and demonstrate the whole process of publishing content of your Neos website on other channels.This will cover basic usage as well as extending it.

Installation:

  • This Package is available on Packagist and Github Download manually or do composer install.
  • Include the Root.ts2 file of the Package in the Root.ts2 file of the Site.

Facebook:

Suppose you/your client has a facebook page and is tired posting the same content on his facebook page,what this basically does is it takes the data from your neos website and posts it on your clients facebook page and provides a link to the website.
Facebook is secure and works on the concept of access tokens,since I'm using a signal slot setup an Oauth popup would not be feasible and posting to a page would be impossible,therefore it is needed to specify the access token in the configuration file.this is a one time thing and may take 5 minutes.
  • Get a facebook Developer account first here
  • Create an app make sure the account is the page admin access.
                             
  • Click Get Access token and make sure you check the manage pages and publish access permissions.
                         
  • The access token which you get is valid only for 60 minutes hence it is required to extend it by visiting this link Convert this access token into a long lived one by https://graph.facebook.com/oauth/access_token?client_id=<your FB App ID>&client_secret= < your FB App secret> &grant_type=fb_exchange_token&fb_exchange_token=< your short-lived access token>
  • Your enter your appid and client secret from your app settings page and enter the access token which you got earlier in the link to get a long lived access token.
  •  Make a Graph API call to see your accounts using the new long-lived access token: https://graph.facebook.com/me/accounts?access_token=< your long-lived access token>

  • This displays all pages managed by you.Note down your pageid and access token for the page .Now you have an access token which is valid forever.
  • For any errors during the process you can debug your access token Debug token.
  • Go to your Configuration.yaml file in the Package and enter the above details.
  • appid and secret are available in you developer account page,user will be the id of your page which you got earlier
  • link will be the link to your server/website
  • caption/name/desc/image are any defaults you want to assign to your facebook post.Leave them blank preferably
  • token will contain your access token.
Congratulations you have successfully set up SocialConnect for facebook.

Let's try it out.
Currently Headline,Text and Document/Page Nodes are supported.

  • Enable Social Connect for a Headline Node and publish.
  • Try it out for other Nodes too!
Extending Social Connect:
  • Sometimes the client has custom NodeTypes which require SocialConnect
  • SocialConnect is built in such a way that it's easy to extend and add/customize NodeTypes
  • Basically the package consists of Helpers,Factories and Overrides.Helpers do all the communicating with the API,Factories make sure the right nodes are fetched and the Overrides define the content of the post.
  • In most cases it is taken care of,if the NodeType is a subclass of an existing one,for example RobertLemke's Blog Plugin work's fine because it inherits the Document type.
  • If you want a new NodeType to behave just like an existing one.you can change the FacebookFactory file to do so.

  •  To customize a way how an Override works,extend the base class FacebookOverride.php make sure all methods are overriden .Make the changes in the Factory file as above.
Social Connect also supports Twitter and Blogger.Please let me know if something is to be done to improve the Project and Request for new NodeType/Social Network Support.


Sunday 10 August 2014

Week 12

This week was less productive compared to the previous weeks because of my semester resuming ,but nevertheless I fixed a major issue which had in the closet since the first few weeks.the textFinder function which is employed in the override for facebook used to find child nodes based the on the given grammar,but if a page contained a page it would traverse that node too,since I was implementing this in FlowQuery there was no way known to me to ignore those pageNodes and successfully find all other child nodes,so I coupled the TYPO3 Content Repository along with FlowQuery ,I get an array of all child nodes satisfying the grammar(node type) and then use TYPO3CR to check if their parent page node is the page concerned.This was I was able to find the best matching nodes for that page.

Next week I wish to implement a multi-threading approach for all the api-calls to improve performance.

Saturday 2 August 2014

Week 11 - Blogception

This title is a homage to 2010's Hollywood blockbuster of
the name Inception,which dwells into the concept of dreams inside
dreams.Usually every weekend i log into blogger and post my updates about that week's work,this week I used the Blogger Posting feature of Social Connect which i just added to post directly from my Neos Website.
This week's progress:
  • Made enhancements to some more code.
  • Added blogger posting to social connect.
  • Providing a username/password combination in the Configuration file along with the name of the blog to post to blogger.
Issues faced:
  • The Blogger posting is still very basic and unstable.
Next Week Goals:
  •  Improve Blogger Posting support complex structures/nodes if possible
  • clean up some more old code.

Catch the progress on Github and comment here for any suggestions/changes.

Sunday 27 July 2014

Week 10 - Fine Tuning Part 2

Ten week's have passed since the coding period began for gsoc 2014,and I spent the last week fine tuning the code which I had written.

Fixes/Improvements:
  • Validation for nodes in fluid,It wont crash if the target nodes do not exist.
  • Logger now saves the log in the Data/Logs folder of the installation.
  • Work in progress to try and integrate blogger api.
Issues:
  • Blogger Api which i'm using is not namespaced,hence using that is quite tricky.

Sunday 20 July 2014

Week 9 - Fine Tuning part1

By the end of last week I was done implementing all the features I set out to implement in my GSOC proposal.So I have put the project on review(link).
  This week I received a suggestion from Simon Schaufelberger to implement a social image feature so that instead of choosing random images in a page while posting,the user can choose which image he wants to be displayed with Faceebook and Twitter,and that will have a separate field in the inspector with image upload.

This Feature was implemented and a few more issues were solved regarding Twitter image sharing.

Saturday 12 July 2014

Week 8 : PreView


Let's recap what I have been doing with this small video.Thanks to this project I'm getting to learn a lot of new technologies every week.This week since I indulged in creating a preview for Facebook and Twitter I got my hands dirty with TypoScript and Fluid for the First time.


Progress:
  • Facebook Preview System for Posting a page,which gives a sample layout with the Post Parameters chosen appropriately.

     
  • Twitter Preview System for Page Posting ,shows a simple template of what it will look like once posted on Twitter.



     
  • I have isolated any Twitter/Facebook CSS from this project as proprietary code would cause licensing issues.
  • Fixed a bug regarding caption limit to Facebook posting.  
Issues:
  • Unable to show image in preview.
  • There are some issues when previewing blank/incomplete pages
Next Week Goals:
  • Find and Fix any bugs relating to this project.and improve performance.
  • Make a tutorial explaining installation .
Catch this project on Github  or packagist.Drop a comment if you have any ideas on making this project better.

Monday 7 July 2014

week 7 :Picture Perfect

Previously Image posting on Facebook used to work with an image link specified in the Config file.this week i set out to dynamically fetch the Image within the Node specified and grab the Web URL related to that link and pass it as a parameter for post.

Progress:
  • Used textFinder() which locates inner TextNodes and made changes to facilitate Image Nodes.
  • Image Nodes are analyzed and converted to resource to get the web URL.
  • Web URL is specified as the post paramter for the image and post is published.
  • some Code Clean up of existing redundant code and fixed a few Bugs of previous builds involving Headline Nodes.
Issues:
  • Lack of an actual server prevented me from testing image link because i have provided http/https links for Facebook/Twitter.
Next week Goals:
  • Implement a system for previewing the post on various channels.
Please post some suggestions if you have any idea on how to improve this project.
Follow Progress GitHub

Monday 30 June 2014

Week 6 : Unagi

Previously I had directly used methods provided by the content repository to search for specific NodeTypes embeded deep inside a parent Node.This week I embarked to use FlowQuery and Eel to locate the specific Nodes.Eel or the Embed Expression Language is a domain specific language which provides a good interface for solving complex expressions.the only way EEL could be used inside a Flow Package(PHP) was through FlowQuery.On a side note the title of this Post comes from Unagi a Japanese fresh water eel.

Progress:
  • Twitter posting now includes a link to the page and shortens any text if it exceeds the character count i.e 140 characters.
  • Facebook and Twitter Override methods were drastically improved by using FlowQuery to find the content nodes for a Page.
  • Page posting for twitter is now enabled which works in a similar manner to Facebook Page Posting and grabs the most appropriate headline/text node in that page for the content of the tweet along with the link to the page.

     
  • I built a simple logging interface to ease development ,this shows the errors with access tokens or any such  important messages.this system is good only for development purposes.

     
Issues Faced:
  • Learning Eel was more complicated than I expected it to be. 
  • Had some issues with newer versions of facebook sdk.had to revert to 4.0.1
Next weeks goals:
  • Next week I intend to tackle the behemoth Image grabbing and posting.
Please post some suggestions if you have any idea on how to improve this project.
Follow Progress GitHub

Friday 20 June 2014

Week 5: Tweet Tweet



Well,I started off this week with the goal of finishing off with Facebook Connect and moving on to Google Plus,I did finish off with Facebook but Google Plus disallows automated posting as of now and I coudn't think of any legal way to post automatically to Google Plus,So I decided to do Twitter and it went like a breeze.

Progress last week:
  • Wrote functions to find a node of a particular type nested deep inside a page,the function works almost perfectly but fails when it encounters a NodeType content collection(teaser).With this Publishing a Page with Facebook will mean that it finds the first headline and uses it as the content for the post,and text for description and the remaining paramters are taken from the page.
  • Working with twitter went like a dream,I used a third party API(codebird) which was really well documented and the best part is that twitter access tokens never expire.
  • After configuring the SDK the remainder of the process was quite similar to Facebook so within no time I could post from my Neos instance to my wall on Twitter.



Issues Faced:
  • Google Plus:Google Plus allowed posting of moments which require you to share the post manually to have a public visibility,which defeats the purpose of automated posting.
  • Getting a verified Twitter developer account took me a day since they don't do mobile verification in India,I had to write to the customer support to get read/write access.
Next weeks Goals:
  • Sharing links/images in the tweet.
  • Tweeting a page.
  • Preparing a tutorial on how to set it all up.
Please post some suggestions if you have any idea on how to improve this project.
Follow Progress GitHub

Sunday 15 June 2014

Week 4 : Override

I dedicated week 4 to build a system such that irrespective of the nodetype considered socialConnect should support it just by small additions to the .yaml file,and larger changes can be tailormade by writing a sub-class which extends the pre-existing override methods.

Progress:
  1. On Communicating with my mentors I was convinced that a checkbox system for the inspector is more suited and is more functional,Hence I changed the code to support checkbox in the inspector and property type was set to boolean.
  2. Instead of having a class(FacebookHelper class) which gets the values of the Facebook post parameters directly,I opted for an indirectly approach where in a base Override class(FbOverride.php) exists which is a default override class for Facebook.
  3. I have added NodeType specific classes for Headline and Page which extend FbOverride but add features of their own,this inclusion required me to write a Factory class(FacebookFactory.php) to generate the right object for a NodeType.
  4. Suppose a new page is created(Download section for neos demo site)and it is shared via socialConnect.The override class(FbPageOverride.php) automatically finds the page name,page link and the headline/text nodetypes and assigns it accordingly to the facebook post parameters as shown.

    here headline becomes the content of the post,the page title becomes the Link title for the post,the text element becomes the description and the caption is queried from the settings.yaml.
  5. Another challenge was providing the link to the page ,now any node published the link to the page will be found and will be conveyed to the facebook post.
Issues:
  1. For now the above features don't tend to work seamless on all pages and cases,some debugging is required .
  2. handling images to facebook post is tricky from a local server . 
Next week goals:
  1. Debug and make fetching text/headline work seamlesslly for all cases and scenarios. 
  2. wind up on Facebook Connect.start Google Plus.
Catch this project on Github  or packagist

Saturday 7 June 2014

Week 3 - UI and advancements

Tension is rising as the midterm evaluation is nearing(23rd June) with my original mid term goal being to finish Social Connect for one social networking site and deploy it for testing.
      I started off last week with the intention of displaying messages on completing of posting/failure but the absense of a framework to do so has put that on hold for now.

Progress for last week:
  • Updated the Facebook Post method to take captions,descriptions and images into consideration, as of now images and description are pre-defined in a yaml file and only the content is fetched from the Node,and posted onto Facebook.
  • For now,the headline NodeType is fully supported and the Inspector UI has been modified for that and a select box is made to select a channel for publishing.

  •  There is an option available to use defaults for name/caption/description for the post or methods can be written to override these defaults as per user discretion.
  • This Package is now available on Packagist repository and can be downloaded easily by adding a line in the composer.json

Issues:
  • Posting exception messages in the interface is still not done.
  • deciding on which node type to consider and handling complex node types.
Next week Goals:
  • Handling complex Nodes like Pages,Chapters etc and image handling if possible.
  • Wind up on Facebook and start working on Google Plus by the end of the week. 
Follow this on https://github.com/hybridNeo/rahul.socialConnect 

Sunday 1 June 2014

Week 2 - Connect

The second week began with me tackling some issues regarding instantiating objects of library files,figures out that i had an mal-aligned doc block which was causing the problem pointed out by the wonderful community ofcourse,after i fixed that things starting falling in line and the progress was smooth as butter.

Progress this week:

  1. First things first,at the time when i started this project Facebook PHP SDK 4.0 was just released and was kind of unstable,But around the last week on May,It had become stable so i deceided to migrate to this better version of the SDK.Which provided more classes and more functionality than the previous one.
  2. I was able to connect to the Facebook services whenever my publishing process generates a signal,and it would post the content of the selected NodeType onto a Facebook page/wall specified.

  3. And the settings regarding Facebook access such as URL,appid etc are stored in a separate settings.yaml file to provide better security.
  4. With respect to the new privacy policy of Facebook it is almost impossible to get an infinitely valid access token.But with respect to Facebook Page which the user is an admin of it is easy to get the access token which lasts forever,i have highlighted all steps to achieve this on the Readme of the Github repo of this package.
  5. Exception handling also done with respect to API calls.
Issues/Problems experienced:
  • I was unable to figure out about the messaging framework of Neos/Flow.
Next Week Goals:

  1. Display appropriate messages on posting to Facebook or display any exceptions.
  2. Analyze the content of the NodeType to check if it has child nodes and images should be considered also.
  3. Inspector UI for SocialConnect.
Follow the repository on https://github.com/hybridNeo/Rahul.SocialConnect

Friday 23 May 2014

Week 1 - A new beginning

The official coding period for GSOC started on 19th May 2014.With regard to my Final Exams getting over on 23rd May,there was a very little I could contribute this week.But nevertheless the excitement level got me coding whenever I had free time.
Progress this week:

  1. Updated installation to dev-master,understood how composer works for downloading packages.
  2. Set up a Basic Flow Package with Slot Service to listen to the publishing process and write all the contents of the respective node.
  3. Used composer to download the library files of Facebook PHP SDK to the Flow Package.
  4. Set up Package.php for the Package to configure the wiring between signal and slot ,and other dependencies. 
Issues/Problem experienced:
  1. Trouble with enterprise level concepts of PHP likes Aspect Oriented Programming.
  2. Trouble initializing objects of library files in the slot.
Next week Goals:
  1. Set up objects of Facebook class in the slot service,and communicate with the Facebook SDK.
  2. Display appropriate messages in the backend.
  3. Handle Exceptions.
Follow the repository on https://github.com/hybridNeo/Rahul.SocialConnect

Monday 19 May 2014

Google Summer of Code @TYPO3

Google Summer of Code was something I heard about in the summer of 2013,with some research about the program I was fairly motivated to apply for the 2014 season.It was February when I got serious thanks to some info sessions by some seniors at college who spoke about the program and its various perks.GSOC was like one of those double decker biscuits .First, we get to code for an open source organization which is amazing knowing the fact that open source is the way of the future,almost every software which is used from my Operating system on my Laptop/Mobile to the Media Players I used were all open sourced,It was high time I gave back to the system.Secondly, while people struggle to get internships at small companies you get to boast around with something that is sponsored by Google,and puts you on their payroll indirectly with a hefty cheque for a student.

My past skills in the field of computer programming included languages like C,Java and PHP,But PHP was my favourite language thanks to it's C like syntax and library support for tools.So while going through the Accepted Organization list found TYPO3 a popular Content Management System to be most suited for my skills.Immediately I contacted the mentors and went through the ideas page,within no time I had set up the working environment for all three flavours of the CMS and liked the futuristic Neos the most,One of the ideas was a multi-channel connector to simultaneously publish posts from the Neos installation itself.I tried building a plugin which would do the same and went through the code-base.One important thing I learnt was that in open-source the main challenge is reading and understanding code written by others.With this in mind and a couple of week of sleepless nights hanging out in the IRC I was able to write my proposal and submit it.

I was very happy when I came to know that my proposal had been accepted and now I had something productive to do in summer other than sleeping all day.I instantly got in touch with my mentors and set up all the required version control softwares and started work.

At the point of writing this post it is the first day of the coding period for GSOC and you can catch all the activity on Github link

I hope to have a productive summer for me and the whole Neos community.