Advertisement
Guest User

BYOND Member data handler

a guest
Oct 27th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. <?php
  2.     function endswith( $str, $sub ) {
  3.         // Lets me quickly check if something ends with something else.
  4.         return ( substr( $str, strlen( $str ) - strlen( $sub ) ) == $sub );
  5.     }
  6.     function ParseMember($keyname) {
  7.    
  8.         // This is a dumbed-down rewrite of the hub data loader written by the Tibbius team. - Nadrew
  9.         // Member data isn't near as complicated as hub data so we don't need all the extra parsing.
  10.         // The full version we use handles member pages too, but it's a bit clunky if you're not going for game data too.
  11.        
  12.         $url = "http://byond.com/members/" . $keyname . "?format=text&long=1"; // Get the long (sans medals) of the user's data.
  13.         // You can add medals too it as well, of course.
  14.        
  15.         // TODO: Add error checking in case an invalid key is passed.
  16.        
  17.         $return_data = array();
  18.        
  19.         $page_data = file_get_contents($url);
  20.        
  21.         $main_array = explode("\n",$page_data); // Split the website data up by newlines first.
  22.         $header = null;
  23.         foreach($main_array as $data) {
  24.             $data = trim($data);
  25.             if(!$data) continue;
  26.             if(!strpos($data,"=")) {
  27.                 // If the data doesn't have an equals sign it's a header.
  28.                 $header = $data;
  29.                 $return_data[$header] = array();
  30.             }
  31.             else {
  32.                 // Otherwise, it's a sub-item.
  33.                 $data_array = explode("=",$data); // An array that splits the variable name from the variable value.
  34.                 $subheader = trim($data_array[0]);
  35.                 $value = str_replace("\"","",trim($data_array[1]));
  36.                 $is_list = strpos($value,"list("); // Handles if the value is a list()
  37.                 if($is_list !== false) {
  38.                     // By turning it into an array()
  39.                     $list_start = $is_list + 5;
  40.                     $list_end = strpos($value,")");
  41.                     $list_text = substr($value,$list_start,$list_end-$list_start);
  42.                     $value = explode(",",$list_text);
  43.                 }
  44.                 $return_data[$header][$subheader] = $value;
  45.             }
  46.         }
  47.         return $return_data;
  48.     }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement