views:

35

answers:

1

Hello guys,

I have a quick question I am currently running a test site of Drupal. I have a module that was written and supported for versions up to 6.16 the test site that I would currently like to use this module in crashes when I enable the module.

I would like to know what basic elements can I look at to ensure that the code is compatible and or if changes are needed.

This module provides integration of a CRM into Drupal for SSO.

I figured if anyone else has come across creating a module to bridge the gap between to systems they might point me in the right direction.

This is the error I receive when I enable the module:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /homepages/22/d223624283/htdocs/drupal6/sites/all/modules/convio/convio.module on line 104

This is the code in the file named convio.module that is giving me a problem:

<?php

/**
 * Classes. (The order is important.)
 */
module_load_include("inc", "convio", "ConvioConstants");
module_load_include("inc", "convio", "ConvioUtils");
module_load_include("inc", "convio", "ConvioConfiguration");
module_load_include("inc", "convio", "ConvioAPIClient");
module_load_include("inc", "convio", "ConvioUser");
module_load_include("inc", "convio", "ConvioLoginHandler");
module_load_include("inc", "convio", "ConvioTokenHandler");


/**
* Implementation of hook_help.
*/
function convio_help() {
if ($path == 'admin/help#convio') {
$txt = 'The Convio module uses the !convio_url API to .';
$link = l('Convio Open', 'http://open.convio.com');
$replace = array('!convio_url' => $link);
return '<p>' . t($txt, $replace) . '</p>';
  }
 }

/**
* Implementation of hook_menu.
*/
function convio_menu() {

// Test
$items['convio/test'] = array(
'title' => 'Convio Test',
'description' => 'Testing.',
'page callback' => 'convio_test',
'file' => 'ui/test.inc',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
 );

// Admin configuration page.
$items['admin/convio/configure'] = array(
'title' => 'Convio Integration',
'description' => 'Settings for the Convio Open API.',
'page callback' => 'drupal_get_form',
'page arguments' => array('convio_configuration_form'),
'file' => 'ui/admin/configure.inc',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);

// SSO Authentication callback.
$items['convio/session/status'] = array(
'title' => 'Convio Session Status',
'description' => 'Validates the Convio user session and updates the Drupal user session.',
'page callback' => 'convio_session_status',
'file' => 'ui/session/status.inc',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
 );

 // SSO Authentication callback.
 $items['convio/session/validate'] = array(
'title' => 'Convio Session Validation',
'description' => 'Validates the Convio user session and updates the Drupal user session.',
'page callback' => 'convio_session_validate',
'file' => 'ui/session/validate.inc',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
 );

// SSO Authentication callback.
$items['convio/session/clear'] = array(
'title' => 'Convio Session Reset',
'description' => 'Clears the Drupal user session.',
'page callback' => 'convio_session_clear',
'file' => 'ui/session/clear.inc',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
 );

 return $items;
}

// Only enable the following hooks if the Open APIs have been configured.
if (ConvioConfiguration::getInstance()->isEnabled()) {

/**
* Implementation of hook_menu_alter()
*
* Alter the user/registration menu item to point to the external
* user account registration page
*/
function convio_menu_alter($items) {

// Always allow access to the user/login.
$items['user/login']['access callback'] = TRUE;

/**
 * Overrides user/register from user.module.
 *
 * $items['user/register'] = array(
 *   'title' => 'Create new account',
 *   'page callback' => 'drupal_get_form',
 *   'page arguments' => array('user_register'),
 *   'access callback' => 'user_register_access',
 *   'type' => MENU_LOCAL_TASK,
 *   'file' => 'user.pages.inc',
 * );
 */
unset($items['user/register']);
$items['user/register'] = array(
                                'title' => 'Sign up',
                                'page callback' => 'convio_user_signup',
                                'access callback' => 'user_register_access',
                                'type' => MENU_CALLBACK,
                                'file path' => drupal_get_path('module','convio'),
                                'file' => 'ui/register.inc',
                                );

// Disable Forgot/Reset Password pages from user.module.
unset($items['user/password']);
unset($items['user/reset/%/%/%']);

// Disable Manage User Profile pages from user.module.
unset($items['user/autocomplete']);
unset($items['user/%user/delete']);

//TODO: alter profile edit form
//unset($items['user/%user_category/edit']);
unset($items['user/%user_category/edit/account']);
unset($items['admin/user/user/create']);

return $items;
}


/**
* Implementation of hook_form_alter.
*
* Replaces the standard login form with a Convio login form.
*/
function convio_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_login_block' || $form_id == 'user_login') {
  ConvioLoginHandler::getInstance()->getLoginForm($form, $form_state, $form_id);
}

return $form;
}


/**
* Implementation of hook_user.
*
* Maps cons_id to the Drupal user account.
*/
function convio_user($op, &$edit, &$account, $category = NULL) {

if ($op == "load") {
  // Make cons_id available from the user.

  $result = db_query("SELECT user_id, cons_id FROM {convio_users} where cons_id = %d", $cons_id);
  $convio_user = db_fetch_object($result);
  if ($convio_user) {
    $account->convio_cons_id = $convio_user->cons_id;
  }

  } else if ($op == "insert") {
  // The user account was created. Map it to the cons_id.

  db_query("INSERT INTO {convio_users} (user_id, cons_id) VALUES (%d, %d)",
           $account->uid,
           $edit["convio_cons_id"]);

  } else if ($op == "after_update") {
  // The user account was updated. 

  $result = db_query("SELECT user_id, cons_id FROM {convio_users} where cons_id = %d", $edit["convio_cons_id"]);
  $convio_user = db_fetch_object($result);
  if (! $convio_user) {
    db_query("INSERT INTO {convio_users} (user_id, cons_id) VALUES (%d, %d)",
             $account->uid,
             $edit["convio_cons_id"]);
  }

  } else if ($op == "delete") {
  // The user account was deleted. Delete any associated Convio mappings.
  // It would be better to have MySQL FK support with cascading deletes.

  db_query("DELETE FROM {convio_users} WHERE user_id = %d", $account->uid);

  } else if ($op == "logout") {

  ConvioLoginHandler::getInstance()->logout();
  }
  }


 /**
 * Implements hook_token_values();
 */
 function convio_token_values($type, $object = NULL) {
  if ($type == 'convio') {
  return ConvioTokenHandler::getInstance()->getValues();
  }
  }

 /**
 * Implements hook_token_list();
 */
 function convio_token_list($type = 'all') {
if ($type == 'convio' || $type == 'all') {
  return ConvioTokenHandler::getInstance()->getList();
  }
 }

/**
* Adds standard includes to every page.
*
* 1) Open API JS lib and init script -> <head>
* 2) Session tracking beacon -> header region
* 3) Keep-alive beacon -> footer region
*/
function _convio_add_includes() {
static $included = FALSE;
if (!$included) {

  $api_config = ConvioConfiguration::getInstance();

  // Establish a new C360 session if one doesn't exist already.
  if (ConvioLoginHandler::getInstance()->newUserSession()) {
    return;
  }

  $api_uri = $api_config->getURI();
  $api_key = $api_config->getPublicKey();

  // TODO: allow the regions to be overriden in the module configuration.
  $region_header = "header";
  $region_footer = "footer";

  // Add Convio Open API JS library and init script.
  drupal_set_html_head('<script type="text/javascript" src="' . $api_uri . '/../api/ConvioApi.js"></script>');

  $script = '<script type="text/javascript">';
  $script .= '  var CONVIO = {};';
  $script .= '  CONVIO.OPEN = new ConvioApiClient("' . $api_key . '","/api_client.html","json");';
  $script .= '</script>';
  drupal_set_html_head($script);

  // Add the session tracking beacon to the body of every page.
  $trackerUrl = url('convio/session/status', array('query' => drupal_get_destination()));
  $tracker = '<script type="text/javascript" src="' . $trackerUrl . '"></script>';
  drupal_set_content($region_header, $tracker);

  // Add a keepalive beacon to the bottom of every page.
  $img = '<img src="' . $api_uri . '/PixelServer" />';
  drupal_set_content($region_footer, $img);
}
    $included = TRUE;
  }

  // Include Convio module JS libraries on every page.
  _convio_add_includes();

} // end: if (ConvioConfiguration::getInstance()->isEnabled())
+2  A: 

Update after new comment:

Could it be that you are still using PHP 4? This would explain the errors - method chaining (meaning to use the '->' operator directly on a function that is supposed to return an object), is only supported since PHP 5, IIRC.

If that is the case, the proper solution would be to switch to PHP 5!

As a temporary solution, you could search for all places where the '->' operator is used directly on a function/method result (functionCall()->...) and insert a separation via another variable. Note that I do not recommend this - PHP 4 is deprecated and does not receive security updates anymore. Running a production environment on it is big no no!


Original answer:

The only T_OBJECT_OPERATOR ('->') in that code seems to be in:

if (ConvioConfiguration::getInstance()->isEnabled()) { ...

so you might want to change that line to something like the following:

$convioConfiguration = ConvioConfiguration::getInstance();
if (is_object($convioConfiguration) && $convioConfiguration->isEnabled()) { ...
Henrik Opel
I will try this now and get back to you.
Matthew
I tried that and now its giving me an error on line 164
Matthew
@Matthew: It looks like you are still using PHP 4 - I updated my answer accordingly.
Henrik Opel
@Henrik Opel... I will run PHP 5 and see what happens.
Matthew
I ran PHP5 and there you have it... thanks!
Matthew

related questions