Reviews synchronization

Synchronization allows you to save the Cackle reviews to the database on your local server storage and indexing by search engines, and update reviews's statuses and messages.

Reviews synchronization in CMS

In Prestashop, Opencart, modules, synchronization, and indexing by search engines(rendering html) reviews exists by default, below there is the description how to make synchronization for every platform.

Synchronization reviews PHP platforms

For PHP sites exists Common PHP lib there indexing by search engines is already implemented, and includes:
  • Every 5 minute cackle requested by that script and reviews save to your local database
  • Html for reviews rendering from database
That library (https://bitbucket.org/cackle-plugin/review-php/get/1.01.zip) is the ready class, which invoked as:

include_once(dirname(__FILE__) . '/cackle_review.php');
$product_id = 12; //id of the product
$a = new CackleReview(true,$product_id);

API Keys must be entered on cackle_admin.php. Here you can also change encoding to Windows-1251(by default utf-8).

Description of reviews's synchronization for other platforms

We recommends to see common Php lib when you make that integration. But inspite of that, below there is a synchronization algoritm.

Review sync api example

{
"id":18874,
"siteId":28333,
"star":5,
"pros":"Pros test",
"cons":"Cons test",
"comment":"Comment test",
"media":"http://media.cackle.me/ba45c8f60456a672e003a875e469d0eb.jpg",
"up":0,
"down":0,
"created":1417596224333,
"status":"approved",
"details":[],
  "author": { "id":72343,
    "email":"email@gmail.com",
    "name":"Author name",
    "www":"https://plus.google.com/link_to_google",
    "provider":"googleplus",
    "openId":"https://plus.google.com/openId"
  }
},
"chan": {
  "id":12024,
  "channel":"13",
  "url":"http://localhost/cackle_review/cackle/page.php",
  "title":""},
  "ip":"91.202.45.183",
  "modified":"1417596224333"
}}

Set up a datastore

To save Cackle reviews in the local database, you need a table with the following fields:

  • id (bigint)
  • product_id (character)
  • pros (text)
  • cons (text)
  • comment (text)
  • date(datetime)
  • status (integer)
  • ip (character)
  • author(character)
  • email (character)
  • avatar (character)
  • is_register(int)
  • approve (int)
  • stars(int)
  • rating (int)
  • user_agent (character)

Synchronization reviews

When the datastore is done, you can start implementing synchronization reviews. The first thing you need to do - is the controller, which would be requested Cackle reviews every 5 minutes. Reviews are available at the following API:

http://cackle.me/api/3.0/review/list.json?id={siteId}&siteApiKey={siteApiKey}&accountApiKey={accountApiKey}&modified={modified}&page={page}&size={size}

Where siteId (siteId), siteApiKey (Site API Key) и accountApiKey (Account API Key) is available in the Admin panel under "Install" below choosing WordPress plugin, as shown in the figure below:

reviews sync reviews sync

The modified parameter is optional. That is, the query will return all reviews that modified more than the modified in the request.

Optional parameter size - returns the defined number of reviews

Optional parameter page - returns reviews from the defined page. It needs when the number of reviews more than size(100 by default).

So we have a controller that every 5 minutes requesting reviews, sorted by id. After each request, you must keep all the reviews in the database or only update statuses. Next save the maximum review_id and modified. Further, in the following query, the maximum modified put in the API query.

Algoritm:

  1. Controller requests
    http://cackle.me/api/3.0/review/list.json?id={siteId}&siteApiKey={siteApiKey}&accountApiKey={accountApiKey}&modified={modified}&page={page}&size={size}
  2. Check response reviews size, and if the size more than {size} in request you should do requests with {page} + 1 until response size will be less than request size. For the next page do step(3):
  3. Next for each review::
    1. If id of received review more than last id saved in DB, the review stored in Db.
    2. If id of received review less than last id in DB, than last modified in DB, only the status and message fields are need to update. And if modified of recieved review more than last modified in DB, then you should update last review modified.
  4. After 5 minutes, find the maximum modified (in the local database):
    $since = "SELECT MAX(modified) FROM reviews"
  5. Again requested API with maximum modified &modified={$since}
  6. In response to all the reviews come review_id which more $since
  7. Moves to point 3, and repeat again

Render reviews

Finally, after Cackle reviews were in your local database, you can render it on HTML page for search engine indexing, as follows:

<div id="mc-review">
    [... output your server-side reviews here ...]
</div>
<script>
    document.getElementById('mc-review').innerHTML = '';
    [... Cackle widget code ...]
</script>