Write your own AutoTweet extension plugin

There are several ways to integrate an extension:

This is the standard way to integrate an extension. You simply install one of the supported plugins. We are constantly adding new plugins and we are glad to add more extensions every day.

Extensions MUST provide content events to fire integration triggers. Otherwise, a modification in the extension has to be implemented to integrate AutoTweet.

Composer editor has its own plugin to create posts. Composer calls the AutotweetComposer (autotweet/autotweetpost) plugin, generating content events like any integrated extension.

The simplest way to integrate an extension is calling this very same plugin, likewise the Composer does:

        require_once JPATH_PLUGINS . '/autotweet/autotweetpost/autotweetpost.php';
        $plugin = JPluginHelper::getPlugin('autotweet', 'autotweetpost');
        $className = 'plgAutotweet' . $plugin->name;

        if (!class_exists($className))
        {
            throw new Exception(JText::_('COM_AUTOTWEET_COMPOSER_DISABLED_ERROR'));
        }

        $dispatcher = JDispatcher::getInstance();
        $plugin = new $className($dispatcher, (array) $plugin);
        $status = $plugin->postArticle($data); 

Ref: administrator/components/com_autotweet/controllers/requests.php, applyAjaxOwnAction function.

If you have official support from the third-party extension author, we recommend you to ask for the new feature to fire content events (a.k.a triggers). In this way, it is going to be easier to maintain the integration. Additionally, if the author implements content triggers, we can implement a new plug-in for you (as part of our commitment to expand our social hub).

If the extension does not have content triggers, you have to look for the right file to introduce the event call and keep it modified/ customized after every extension update. For instance, BT Property author recommends to add the following code in file /administrator/components/com_bt_property/models/property.php, save() function:

$dispatcher = JDispatcher::getInstance();
$row = JTable::getInstance('Property', 'Bt_propertyTable');
$dispatcher->trigger('onAfterContentSave', array(
    &$row,
    $pid
));

There are several cases where you need to create or customize your own AutoTweet plugin:

  • You have created your own extension
  • Your project has very specific requirements about how a Post must be created

To start in the quickest way:

  • Pick one plugin, similar to what you are looking for. For instance, AutoTweet-WebLinks is very simple or AutoTweet-BT Property plugin, a recently added plugin.
  • Duplicate and rename the files,
  • Replace the identification strings to create your own plugin. For example, if you choose Autotweet-JoomBah plugins, you have to replace JoomBah, JOOMBAH, joombah and Joombah with your own identification strings.
  • Build on top of this plugin your own modifications. There are several common practices and topics in all plugins: identify content events, new content and/ or modified content, message templating, category management (Joomla! core categories or custom categories, single/ multiple categories), SEF management and two-steps post creation (more on this below).

If you are unsure how to proceed and these steps are very complex for you (or you do not have time), you can simply modify our plugin (and maintain the modification along updates).

If you have any question, please, send us a ticket, we have extensive experience solving classic plug-in issues.

Some plugin guidelines:

  • AutoTweet plugins extend PlgAutotweetBase base class. This class has several utility functions used to detect images, filter by category, clean texts, load the author, etc.
  • When the extension fires a Joomla! event, for instance when an article is saved, the plugin catches the event to create a new queue item, calling postStatusMessage.
  • If the extension raises a specific event, like onAfterContentSave, it is a straighforward "event - post" relation.
  • In some rare cases, the plugin can catch the onAfterRoute event and process the URL to detect the new content item and save a new message. (Not Recommended)
  • Alternatively, content polling can be implemented to detect new content items and generate the associated messages (checking the extension tables at database level).
  • Finally, when Requests are processed to create channel specific Posts, the plugin is called, to fill additional Post information (getData or getExtendedData functions).

Posts are created and delivered in several steps. This procedure has two main advantages:

  • It allows to support and accommodate many content creation workflows
  • It avoids server overload in low-entry hosts

Regarding content creation workflows, each extension has its own way to define content. In the best case, an article is created in a single step. In other cases, content creation event is raised when the object is partially defined (e.g. without images). To support these cases, AutoTweet has a second post definition chance, calling getExtendedData function.

The element "id" of the plugin must begin with "autotweet" (AutoTweet is using this ID to detect the plugins). The element "id" is specified in plugin xml manifest file. In the following sample, the element "id" is "autotweetcontent":

filename plugin="autotweetcontent"

The classname of the plugin must follow the standard Joomla! naming convention for plugins: Prefix "Plg", plugin folder (e.g. System) and element "id". In our example, the plugin is of type "system" and the element "id" is "autotweetcontent", generating the classname "PlgSystemAutotweetContent".

The plugin integration is perfect if the extension supports Joomla! events for content integration.

However, if the extension does not provide integration events, AutotweetAPI can be called from the extension to insert a message into the Request queue.

This file has to be included to integrate the API and AutotweetAPI::insertRequest must be called.

File: administrator/components/com_autotweet/api/autotweetapi.php

Description: Main method to insert new requests.

Description: sample external call to save Joocial advanced attributes

Description: sample external call to save AutoTweetNG content request

We provide an extensive list of plugins to integrate +40 extensions. These plugins are integrated with events/triggers provided by each extension as third-party integration.

If you need to integrate a new extension, New Plugin Best-Effort Support: We love to integrate new extensions as the way to improve our social hub beyond its limits. If we don't have a plug-in, we add it in product roadmap to release ASAP (in practice 1-2 weeks).

If an extension does not have integration events/triggers, you can contact the author to add them. It is simply a new call in the integration point:

Joomla! Docs: Triggering content plugins in your extension - http://docs.joomla.org/Triggering_content_plugins_in_your_extension

If there is no possible integration, there is also a last way to implement an integration, a direct call to AutoTweetNG API from the component. The API is implemented as a single function where all social requests are recorded. Calling AutoTweetNG API

To call the API:

if (!defined('AUTOTWEET_API'))
{
         include_once JPATH_ADMINISTRATOR . '/components/com_autotweet/api/autotweetapi.php';
}

$id = AutotweetAPI::insertRequest(
         $productId,          // A Request Unique ID (only used to check duplication)
         'autotweetpost',     // Insert the request as a manual post
         $now,                // Publication Date
         $title,              // Title
         $typeinfo,           // A Type ID (only informative)
         $url,                // Url
         $image_url,          // Image Url
         $native_object,      // A content representation  (only informative)
         $advanced_attrs      // Advanced post attributed for Scheduling, Agenda, etc
    );

E-Shop is a well-known Joomla! extension, a powerful Joomla! Shopping Cart / e-Commerce extension, EShop - Joomla! Extensions Directory. However, it does not provide external integration.

We have included an example of integration in AutoTweetNG API based on our experience with E-Shop. We have developed two functions to insert a Social Request into AutoTweet queue and additional scheduling attributes de Joocial features. In this example, Manual Post plugin must be enabled to process the social request.

In /components/com_autotweet/api/autotweetapi.php, you can find:

/**

* joocialIntegration
*
* @param int $productId Param
*
* Example of how to save Joocial Advanced attributes
* Copy-paste into your extension, and customize freely
*
* @return void
*/
private static function joocialIntegration($productId)

/**
* sampleAutoTweetNGIntegration
*
* @param int $productId Param
* @param array &$data Param
*
* Example of how to save AutoTweetNG Request
* Copy-paste into your extension, and customize freely
*
* @return void
*/
private static function sampleAutoTweetNGIntegration($productId, &$data)

Based on these examples, an integration with E-Shop is simply implemented adding into the file where the product is saved (administrator/components/com_eshop/models/product.php, line 390):

// Call to AutoTweetNG API
$this->joocialIntegration($productId);
$this->autoTweetNGIntegration($productId, $data);

As you can see, in the sample functions, E-Shop product information must be accessed to retrieve the right information to be published. Also, an additional step is required to access the multi-language product data.

In this article, we have reviewed the three possible alternatives to generate Social Requests from different sources:

  • Available extension plugins
  • Adding Triggers into an extension
  • Adding a direct call to AutoTweetNG API