Social Poster is the add-on for ExpressionEngine 2 that allows automatic updates to be sent to social networks when user performs certain actions. The user need to have social account(s) linked to his EE profile using Social Login PRO, which is required for Social Poster to work.
The action user makes must be associated with an extension hook. You can disable posting on certain hooks as well as use different templates. It is also easy to create your own posting rules by following the example.
Social Login PRO is REQUIRED for this add-on to work.
REQUIREMENTS: the user has to have social network account added to his EE profile using Social Login Pro and "Send status updates from user's account about his activity" must be checked in Social Login Pro settings.
<li><a href="#settings">Settings & configuration</a></li>
<li><a href="#permissions">Default Permissions tag</a></li>
<li><a href="#permissions-detailed">Detailed Permissions tag</a></li>
<li><a href="#custom">Extending with custom hooks</a></li>
↑Settings & configuration
Settings page consists of 2 sections: 'default posting settings' and 'hooks and templates'.
'Default posting settings' lists all social networks supported for posting by Social Login Pro (even if you don't have keys for all of them yet). You can select to which networks you want the posts to be made when user performs actions on your site. The user can set his personal permissions for than using permissions and permissions_detailed template tags.
'Hooks and templates' section displays the list of installed hooks and associated posting templates. Each hook represents certain user action performed on site. The templates are set separately for each hook, there are 2 fields: for post text and for link. The available variables are listed at the left.
If your ExpressionEngine installation is using MSM, the setting are saved for each site separately.
↑Default Permissions tag
{exp:social_poster:default_permissions} tag is used to present user a form in which he can allow or disallow posting to each social network that is added to his account. If your ExpressionEngine installation is using MSM, the permissions are saved for each site.
{exp:social_poster:default_permissions return="SAME_PAGE"}
{permissions}
<p>
Allow posting to {field_label}?
<input type="radio" value="y" name="{field_name}" {selected_yes} /> Yes
<input type="radio" value="n" name="{field_name}" {selected_no} /> No
</p>
{/permissions}
<input type="submit" value="Save" />
{/exp:social_poster:default_permissions}
Tag parameters:
- return — a page to return after submitting form. Can be a full URL or URI segments.
Use return="SAME_PAGE" to return user to the page used to display form. - id — form ID (defaults to 'status_updates_form')
- class — form class (defaults to 'status_updates_form')
- name — form name (defaults to 'status_updates_form')
- ajax="yes" — process form in AJAX mode (will return success/error text without formatting)
All variables must be placed inside {permissions}...{/permissions} pair. You need to use radio buttons type of input to make sure the preferences will be saved correctly.
Variables:
- field_name — field name, to be used as value of "name" parameter of input tag
- field_label — field label
- selected_yes — make radio button selected if posting is allowed
- selected_no — make radio button selected if posting is not allowed
↑Detailed Permissions tag
{exp:social_poster:permissions} tag will create a form in which the user can can allow or disallow posting to each social network upon each suported event/user action. Total and precise control of what is being posted, separate setting for each network/action pair. If your ExpressionEngine installation is using MSM, the permissions are saved for each site.
{exp:social_poster:permissions return="SAME_PAGE"}
{permissions}
<p>
{field_label}
<input type="radio" value="y" name="{field_name}" {selected_yes} /> Yes
<input type="radio" value="n" name="{field_name}" {selected_no} /> No
</p>
{/permissions}
<input type="submit" value="Save" />
{/exp:social_poster:permissions}
Parameter and variables are exactly the same that for {exp:social_poster:default_permissions} tag.
↑Extending with custom hooks
You can easily extend the module to support custom actions by creating your own hooks.
If you need integration with some well-known ExpressionEngine add-on, feel free to request it by sending email to [email protected]
First of all, make sure that the module that is processing user's action contain some extension hook. If it does not, you can either request developers to add it or add it yourself.
Next, familarize yourself with code in /hooks/entry_submission_end.php file. It contains comments that should help you to get started.
Create new file in /hooks/ directory (you may copy entry_submission_end.php). Name the file after name of extension hook that will trigger it. Example: 'entry_submission_end' is the extension hook which is called when entry is submitted. We want it to also trigger Social Poster, so we name the file 'entry_submission_end.php'
The class name will be (first letter capitalized) name of extension hook + '_sp_hook' prefix. Your class should contain constructor and at least one function, named - again - after extension hook (in our case, entry_submission_end()). It is of course recommended to also have all other functions and variables found in example.
The purpose of 'main' (entry_submission_end()) function is to build text and links to be posted and to actually post it.
You mostly need to modify only one part of function, which is used to create array of variables which will be used to transform templates into actual message and link. You'll need to know a tiny bit of PHP to do it, but as you can see in example, it is usually just couple of lines of code.