I'd like to add Hyves to the list. Is this possible?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

the_loeki’s picture

Version: 7.x-1.0-beta8 » 7.x-1.0-beta13
Issue tags: ++patch
FileSize
26.67 KB

I've preliminarily added Hyves as a platform. I'll test & setup the sharing part tomorrow.

Added to socialmedia.platforms.inc:

function socialmedia_hyves_platform_info() {
  $platforms = array();
  $platforms['hyves'] = array(
    'title' => t('Hyves'),
    'description' => t('URL to your Hyves profile'),
    'homepage' => 'http://www.hyves.nl/',
    'redirect path' => 'hyves',
    'parser callback' => 'socialmedia_hyves_parser',
    'tokens callback' => 'socialmedia_hyves_tokens',
  ); 
  $platforms['hyves']['form'] = array(
    'title' => t('Hyves profile'),
    'description' => t('URL to your Hyves profile'),
  );
  $platforms['hyves']['tokens']['multi'] = array(
    'hyves_url' => array(
      'name' => t("Hyves profile url"), 
      'description' => t("URL to Hyves profile."),
    ),
    'hyves_url-brief' => array(
      'name' => t("Hyves profile url (brief)"), 
      'description' => t("URL to Hyves profile without protocol."),
    ), 
    'hyves_username' => array(
      'name' => t("Hyves name"), 
      'description' => t("Hyves profile name"),
    ),   
  );
  return $platforms;  
}

function socialmedia_hyves_parser($values, $scope = 'site') {
  $profile = array('url' => '', 'username' => '');
  $str = $values['url'];
  $pattern = '/(?:http(s)?:\/\/)?(\w+)\.(hyves\.nl\/)?(\w+)+/i';
  if (!preg_match($pattern, $str, $matches, PREG_OFFSET_CAPTURE)) {
    if (trim($values['url'])) {
      form_set_error('input_hyves_url', t('Hyves URL invalid.'));
    }
    return FALSE;    
  }
  $a = explode('.hyves.nl', $str);
  $profile['url'] = $a[0] . '.hyves.nl/';
  if (isset($values['username']) && trim($values['username'])) {
    $profile['username'] = $values['username'];
    return $profile;
  } else {
  	$profile['username'] = $a[0];
	return $profile;
  }

  //Shouldn't get here...
  form_set_error('input_hyves_username', t('Cannot derive username for this type URL. Please provide a username.'));
  return FALSE;
}

function socialmedia_hyves_tokens($key, $profile) {
  switch ($key) {
  // Simple key values on the node.
    case 'url':
      return 'http://' . $profile['url'];
    case 'url-brief':
      return $profile['url'];
    case 'username':
      return $profile['username'];
  }
  return '';
}

(sans the PHP tags of course)

And added

$platforms = array_merge($platforms, socialmedia_hyves_platform_info()); 

To the array_merge sequence at the top in socialmedia_socialmedia_platform_info().