Introduction

The following snippet pulls a myspace event feed into a Drupal page.

Requires your PHP Input Filter to be available and the PHP function file_get_contents. You can check to see if your host allows the use of file_get_contents by using a standard phpinfo file.

Instructions

  1. Create a normal Drupal page by going to CREATE CONTENT -> PAGE
  2. Pasted the entire snippet below into the body area
  3. Edit the myspace link variable at the top of the snippet to match the link your myspace.com events page
  4. Expand the INPUT FILTER option and select PHP Input
  5. Click on SUBMIT
  6. Style output to suit
<?php

/**
* The following displays pulls a myspace events page into a Drupal site
* 
* Edit the $myspace_link variable to match the events listing you want to use.
*
*/

$myspace_link = 'http://collect.myspace.com/index.cfm?fuseaction=bandprofile.listAllShows&friendid=34877822&n=Cashier+No.9';


// is file_get_contents installed?
if (!function_exists('file_get_contents')){
 print theme(page, "Sorry, this snippet won't work because file_get_contents is not installed or available on your hosting package.");
 exit;
 }



function readPage ($url)
{
$html = file_get_contents($url);
$arrayFull = explode('<table width="615" border="0" cellspacing="0" cellpadding="0" align="center">', $html); 
array_shift($arrayFull);
$i = count($arrayFull); 
$j = $i-1; 
$final = $arrayFull["$j"]; 
array_splice($arrayFull, "$j");
$clean = explode('<hr color="#6699CC" width="100%" align="center" size="2" noshade />', $final);
array_splice($clean, 1);
$merged = array_merge($arrayFull, $clean);
$iter = 0;
foreach ($merged as $event) {
  if (eregi('<input type="hidden" name="calEvtDateTime" value="(.*)">', $event, $match));
  { array_shift($match);
				foreach ($match as $time)
					{
						$position_event = strpos($time, '"');
						$time_final = substr_replace($time, '', $position_event);
						$month = substr($time_final, 0, 2);
						$day = substr($time_final, 3, 2);
						$year = substr($time_final, 6, 4);
						$hour = substr($time_final, 11, 2);
						$minute = substr($time_final, 14,2);
						$unix = mktime($hour,$minute,'00',$month,$day,$year);
						// $rfc = date(r, $unix);
						$time_array[$iter] = $unix;
					}
				}
	// make array of cities
	if (eregi('<input type="hidden" name="calEvtCity" value="(.*)">', $event, $match))
			{
			array_shift($match);
				foreach ($match as $city)
					{
						
						$position = strpos($city, '"');
						$city_final = htmlspecialchars(substr_replace($city, '', $position));
						$city_array[$iter] = $city_final;
					}
			}

	// make array of location/venue		
	if	(eregi('<input type="hidden" name="calEvtLocation" value="(.*)">', $event, $match));
			{
			array_shift($match);
				foreach ($match as $venue)
					{
						$position_venue = strpos($venue, '"');
						$venue_final = htmlspecialchars(substr_replace($venue, '', $position_venue));
						$venue_clean = ereg_replace('&#233;', 'e', $venue_final);
						$venue_array[$iter] = $venue_clean;
					}
					
			  }

	// make array of street		
	if	(eregi('<input type="hidden" name="calEvtStreet" value="(.*)">', $event, $match));
			{
			array_shift($match);
				foreach ($match as $street)
					{
						$position_street = strpos($street, '"');
						$street_final = htmlspecialchars(substr_replace($street, '', $position_street));
						$street_array[$iter] = $street_final;
					}
					
			  }
	
	// make array of description		
	if	(eregi('<br /><br />(.*)</td>', $event, $match));
			{
			array_shift($match);
				foreach ($match as $description)
					{
						$description_array[$iter] = htmlspecialchars(preg_replace('([\n])', '<br />', $description));
					}
					
			  }			  
			  	$iter++; 
	}
	

$event_number = count($merged); 
$f = 0; 

while ($f < $event_number)
	{
		print '<div class="myspaceevent">';
		print '<div class="venue"><h3>' . $venue_array[$f] . ' - ' . $street_array[$f] . ',' . $city_array[$f] . '</h3></div>';
		print '<div class="description"><p>' . $description_array[$f] . '</p></div>';
		print '<div class="date"><p>' . date("F - d - Y", $time_array[$f]) . '</p></div>';
		print '<div class="link"><p><a href="' . htmlspecialchars($url) . '">link</a></p></div>';
		print '</div>';
		$f++;	
	}
}

readPage ($myspace_link);

?>

Example output

For reference and CSS purposes, the following is an example event that the snippet generates:

<div class="myspaceevent">
  <div class="venue">
    <h3>Belfast Waterfront Age: 6-12 years - ,Belfast</h3>
  </div>
  <div class="description">
    <p>Tiny Trans Presents Pre- Teenage Kicks with Cashier No.9 &lt;br /&gt;&lt;br /&gt;Age: 6 - 12 yrs&lt;br /&gt;
&lt;br /&gt;With Escape Act &amp; The Benjamins</p>
  </div>
  <div class="date">
    <p>May - 30 - 2009</p>
  </div>
  <div class="link">
    <p><a href="http://collect.myspace.com/index.cfm?fuseaction=bandprofile.listAllShows&amp;friendid=34877822&amp;n=Cashier+No.9">link</a></p>
  </div>
</div>

Notes:

  1. Based on the following snippet, which includes comments: http://www.juicyfly.com/playground/myspace.php
  2. In Drupal 6.x and later versions you need to enable the PHP INPUT FILTER module (which is part of the core Drupal download) for the PHP Input option to be available. Be very careful which roles have access to this filter - it should *only* be available to site admins.
  3. Use at your own risk. It's impossible to lock a page on drupal.org to stop others editing it and changing the code, so test on a demo site before using on a live site.