Jump to content

[SOLVED] please help me debug this script


Blesbok

Recommended Posts

*/
function goodreads_block($op='list' , $delta=0, $edit=array())  {
  switch ($op)  {
    case 'list':
      $blocks[0]['info'] = t('Goodreads Bookshelf');
      return $blocks;
    case 'view':
      $url = 'http://www.goodreads.com/review/list_rss/'
            .'398385'
            .'?shelf='
            .'history-of-philosophy';
      $blocks['subject'] = t('On the Bookshelf');
      $blocks['content'] = _goodreads_fetch_bookshelf($url);
      return $blocks;
  }
}

/**
*
* Retrieve information from the Goodreads bookshelf XML API.
* 
* This makes an HTTP connection to the given URL, and
* retrieves XML data, which it then attempts to format
* for display.
*
* @param $url
* URL to the goodreads bookshelf.
* @return
* String containing the bookshelf.
*/
function _goodreads_fetch_bookshelf($url, $num_items=3)  {
  $http_result = drupal_http_request($url);

  if ($http_result->code == 200)  {
    $doc = simplexml_load_string($http_result->data);
    if ($doc === false)  {
      $msg = "Error parsing bookshelf XML for %url: %msg.";
      $vars = array('%url'=>$url, '%msg'=>$e->getMessage());
      watchdog('goodreads', '$msg, $vars, WATCHDOG_WARNING);
      return t("Getting the bookshelf resulted in an error.");
    return _goodreads_block_content($doc, $num_items);

    // Otherwise we don't have any data
  }
  else {
    $msg = 'No content from %url.';
    $vars = array('%url' => $url);
    watchdog('goodreads', $msg, $vars, WATCHDOG_WARNING);
    return t("The bookshelf is not accessible.");
  }
}

 

i get the error: PHP Parse error: syntax error, unexpected T_STRING in the line:

    // Otherwise we don't have any data

Link to comment
https://forums.phpfreaks.com/topic/133047-solved-please-help-me-debug-this-script/
Share on other sites

corrected

 

<?php

function goodreads_block($op='list' , $delta=0, $edit=array())  {
  switch ($op)  {
    case 'list':
      $blocks[0]['info'] = t('Goodreads Bookshelf');
      return $blocks;
    case 'view':
      $url = 'http://www.goodreads.com/review/list_rss/'
            .'398385'
            .'?shelf='
            .'history-of-philosophy';
      $blocks['subject'] = t('On the Bookshelf');
      $blocks['content'] = _goodreads_fetch_bookshelf($url);
      return $blocks;
  }
}

/**
*
* Retrieve information from the Goodreads bookshelf XML API.
*
* This makes an HTTP connection to the given URL, and
* retrieves XML data, which it then attempts to format
* for display.
*
* @param $url
* URL to the goodreads bookshelf.
* @return
* String containing the bookshelf.
*/
function _goodreads_fetch_bookshelf($url, $num_items=3)  {
  $http_result = drupal_http_request($url);

  if ($http_result->code == 200)  {
    $doc = simplexml_load_string($http_result->data);
    if ($doc === false)  {
      $msg = "Error parsing bookshelf XML for %url: %msg.";
      $vars = array('%url'=>$url, '%msg'=>$e->getMessage());
      watchdog('goodreads', $msg, $vars, WATCHDOG_WARNING);
      return t("Getting the bookshelf resulted in an error.");
    return _goodreads_block_content($doc, $num_items);

    // Otherwise we don't have any data
  	}
  }
  else {
    $msg = 'No content from %url.';
    $vars = array('%url' => $url);
    watchdog('goodreads', $msg, $vars, WATCHDOG_WARNING);
    return t("The bookshelf is not accessible.");
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.