You are here

function wordstream_include_api_class in WordStream Keyword Tools 6

Same name and namespace in other branches
  1. 7 wordstream.module \wordstream_include_api_class()
2 calls to wordstream_include_api_class()
wordstream_admin_settings in ./wordstream.admin.inc
Displays the form for the standard settings tab.
wordstream_get_keyword_data in ./wordstream.module
Generates keyword search volume data from WordStream

File

./wordstream.module, line 67

Code

function wordstream_include_api_class() {

  /*
  include_once(drupal_get_path('module', 'wordstream') . '/lib/class.wordstream.inc');
  $un = variable_get('wordstream_username', '');
  $pw = variable_get('wordstream_password', '');
  $wordstream = new WordStream($un, $pw);

  if (!$_SESSION['wordstream']['sid']) {
    $ret = $wordstream->login();
    list($un, $sid) = explode(':', $ret);
    $_SESSION['wordstream']['sid'] = $sid;
  }
  return $wordstream;
  */
  $files['module_path'] = './' . drupal_get_path('module', 'wordstream') . '/lib/class.wordstream.inc';
  if (module_exists('libraries') && ($p = libraries_get_path('wordstream'))) {
    $files['libraries_path'] = './' . $p . '/class.wordstream.inc';
  }
  foreach ($files as $f) {
    if (file_exists($f)) {
      $file = $f;
      break;
    }
  }
  if (!$file) {
    $msg = t('The WordStream module requires the WordStream API class. ');
    $msg .= l(t('Download the class here.'), 'https://api.wordstream.com/doc/sample_code?doc=wordstream_api.php&label=WordStream%20API%20Sample%20Code', array(
      'attributes' => array(
        'target' => 'alchemy',
      ),
    ));
    $msg .= "<br><br>";
    if ($files['libraries_path']) {
      $msg .= t(' Save the file on your server in a folder named "wordstream" under the libraries directory; %path.', array(
        '%path' => $files['libraries_path'],
      ));
    }
    else {
      $msg .= t(' Save the file on your server in a folder named "lib" under the WordStream module directory; %path.', array(
        '%path' => $files['module_path'],
      ));
    }
    if ($analysis) {
      $analysis['messages'][] = contentanalysis_format_message($msg, 'error');
    }
    else {
      drupal_set_message($msg, 'error');
    }
    return FALSE;
  }
  require_once $file;
  $un = variable_get('wordstream_username', '');
  $pw = variable_get('wordstream_password', '');
  $wordstream = new WordStream($un, $pw);
  if (!$_SESSION['wordstream']['sid']) {
    $ret = $wordstream
      ->login();
    list($un, $sid) = explode(':', $ret);
    $_SESSION['wordstream']['sid'] = $sid;
  }
  return $wordstream;
}