You are here

public function AddThis::fetchCSV in Drupal Most Popular 6

Makes a call to the AddThis.com server and parses the CSV response.

Parameters

string $dimension: The dimension we're interested in. It must be null or one of:

  • content
  • continent
  • country
  • domain
  • service

string $params: Additional parameters to send. The following are allowed:

  • period: 'day', 'week' or 'month'
  • domain: any URL domain
  • service: 'email'

Return value

array An array of associative arrays, each containing:

  • shares: The number of times the page was shared.
  • url: The URL of the page.
1 call to AddThis::fetchCSV()
AddThis::getNodeEmailCount in modules/mostpopular_addthis/mostpopular_addthis.classes.inc
Gets the most emailed nodes from AddThis.com for the given period of time.

File

modules/mostpopular_addthis/mostpopular_addthis.classes.inc, line 119
Provides a connector to the AddThis.com API.

Class

AddThis
@file Provides a connector to the AddThis.com API.

Code

public function fetchCSV($dimension = '', $params = array()) {
  $out = array();
  $this
    ->fetch($dimension, 'csv', $params);

  // If we got a result, parse the CSV fields
  if (empty($this->result->error)) {
    $lines = preg_split('(\\r|\\n|\\r\\n)', $this->result->data);
    $headers = array();
    foreach ($lines as $line) {
      $line = trim($line);
      if (!empty($line)) {

        // If this is the first row, use it as the headers
        if (empty($headers)) {
          $parts = split(',', $line);
          $headers = $parts;
        }
        else {
          $parts = split(',', $line, count($headers));
          $data = array();
          foreach ($parts as $i => $part) {
            $data[$headers[$i]] = $part;
          }
          $out[] = $data;
        }
      }
    }
  }
  else {

    // Get the message type
    if (preg_match("/<b>message<\\/b> <u>(.+?)<\\/u>/", $this->result->data, $matches)) {
      drupal_set_message($matches[1], 'error');
    }
  }
  return $out;
}