aaaaaa123456789 icon

Acid Chat template processing code

aaaaaa123456789 | PRO | 02/18/13 11:33:38 PM UTC | 0 ⭐ | 458 👁️ | Never ⏰ | []
PHP |

16.82 KB

|

None

|

0 👍

/

0 👎

<?php
 
include "ptempl.php";
 
function get_PR2code () {
  // returns the PR2 embed code
  $code = '<embed width="550" height="400" base="http://external.kongregate-games.com/gamez/0001/0110/live/" 
 
src="http://external.kongregate-games.com/gamez/0001/0110/live/embeddable_10110.swf" type="application/x-shockwave-flash"></embed>';
  return array('width' => '550', 'height' => '400', 'contents' => $code);
}
 
function get_announcebox_URI () {
  return 'http://acidchat.comuf.com/announce.php';
}
 
function get_backchat() {
  // returns the backup chat embed code 
  $code = '<object width="400" height="400" id="obj_1313089480453"><param name="movie" value="http://acidbackup.chatango.com/group"/><param 
 
name="wmode" value="transparent"/><param name="AllowScriptAccess" VALUE="always"/><param name="AllowNetworking" VALUE="all"/><param 
 
name="AllowFullScreen" VALUE="true"/><param name="flashvars" value="cid=1313089480453&b=60&f=50&l=999999&q=999999&r=100&s=1"/><embed 
 
id="emb_1313089480453" src="http://acidbackup.chatango.com/group" width="400" height="400" wmode="transparent" allowScriptAccess="always" 
 
allowNetworking="all" type="application/x-shockwave-flash" allowFullScreen="true" 
 
flashvars="cid=1313089480453&b=60&f=50&l=999999&q=999999&r=100&s=1"></embed></object>';
  return array('width' => '400', 'height' => '400', 'contents' => $code);
}
 
function get_lightIRC ($style) {
  switch ($style) {
  case 'black':
    $page = 'black';
    break;
  case 'blue':
    $page = 'blue';
    break;
  case 'darkorange':
    $page = 'do';
    break;
  case 'green':
    $page = 'green';
    break;
  case 'lightblue':
    $page = 'litblue';
    break;
  case 'yellow':
    $page = 'yellow';
    break;
  case 'default': default:
    $page = 'index';
  }
  $code = '<iframe src="http://acidch.at/clients/lightIRC/' . $page . '.html" style="width:550px; height:400px;">Sorry, if this shows up, you have 
 
to update your browser.</iframe>';
  return array('width' => '550', 'height' => '400', 'contents' => $code);
}
 
function get_eris($mode) {
  $code = '<iframe src="http://acidch.at/clients/eris_' . $mode . '" width=550 height=400 frameborder=0 border=0 scrolling=no scrollbar=no>Sorry! 
 
You need to update your browser to use the chat.</iframe>';
  return array('width' => '550', 'height' => '400', 'contents' => $code);
}
 
function get_chat_lightIRC ($pagemode) {
  // returns the code for the chat, on the new client, lightIRC
  switch ($pagemode) {
  case 1: 
    return get_lightIRC('black');
  case 2:
    return get_lightIRC('blue');
  case 3:
    return get_lightIRC('darkorange');
  case 4:
    return get_lightIRC('green');
  case 5:
    return get_lightIRC('lightblue');
  case 6:
    return get_lightIRC('yellow');
  case 7:
    return get_chat_lightIRC(mt_rand(0, 6));
  case 0: default:
    return get_lightIRC('default');
  }
}
 
function get_chat_eris ($pagemode) {
  // returns the code for the chat, on the client Eris
  switch ($pagemode) {
  case 8:
    return get_eris('dfl'); // default
  case 9:
    return get_eris('blu'); // blue
  case 10:
    return get_eris('gry'); // gray
  case 11:
    return get_eris('lb'); // light blue
  case 12:
    return get_eris('wod'); // wood
  case 13:
    return get_eris('pnk'); // pink
  case 14:
    return get_chat_eris(8 + mt_rand(0, 5));
  default:
    return get_chat_eris(8);
  }
}
 
function get_chat ($pagemode) {
  /* selects an IRC client for embedding */
  if ($pagemode >= 0 && $pagemode <= 7) return get_chat_lightIRC($pagemode);
  if ($pagemode >= 8 && $pagemode <= 14) return get_chat_eris($pagemode);
  if ($pagemode == 15) return get_chat(mt_rand(0, 14));
  if ($pagemode == 16) return get_backchat();
  if ($pagemode == 17) return null;
  return get_chat_lightIRC(0);
}
 
function get_game ($val) {
  // returns the code for the selected value for Game
  switch ($val) {
  case 1:
    return get_PR2code();
  case 0: default:
    return null;
  }
}
 
function get_background ($bgnumber) {
  $path = '/backgrnd';
  switch ($bgnumber) {
  case 0:
    // default
    return array('type' => 1, 'image' => "$path/bg_dflt.gif", 'foreground' => '#ffffff');
  case 1:
    // creation
    return array('type' => 1, 'image' => "$path/bg_crtn.jpg", 'foreground' => '#000000');
  case 2:
    // pr2 fields
    return array('type' => 1, 'image' => "$path/bg_pr2fd.png", 'foreground' => '#000000');
  case 3:
    // pr2 space
    return array('type' => 1, 'image' => "$path/bg_pr2sp.png", 'foreground' => '#ff0000');
  case 4:
    // fire
    return array('type' => 1, 'image' => "$path/bg_fire.png", 'foreground' => '#000000');
  case 5:
    // space
    return array('type' => 1, 'image' => "$path/bg_space.jpg", 'foreground' => '#000000');
  case 6:
    // black
    return array('type' => 0, 'background' => '#000000', 'foreground' => '#ffffff');
  case 7:
    // dark red
    return array('type' => 0, 'background' => '#800000', 'foreground' => '#ffffff');
  case 8:
    // dark blue
    return array('type' => 0, 'background' => '#000080', 'foreground' => '#ffffff');
  case 9:
    // dark green
    return array('type' => 0, 'background' => '#005000', 'foreground' => '#ffffff');
  case 10:
    // dark orange
    return array('type' => 0, 'background' => '#bf590e', 'foreground' => '#ffffff');
  case 11:
    // space 2
    return array('type' => 1, 'image' => "$path/bg_spac2.gif", 'foreground' => '#ffffff');
  case 12:
    // PR3K firestone
    return array('type' => 1, 'image' => "$path/bg_3k_fs.jpg", 'foreground' => '#ffffff');
  case 13:
    // PR2 lobby
    return array('type' => 1, 'image' => "$path/pr2lobby.png", 'foreground' => '#000000');
  case 14:
    // PR2 city
    return array('type' => 1, 'image' => "$path/pr2_city.png", 'foreground' => '#ffffff');
  case 15:
    // PR2 rocky field
    return array('type' => 1, 'image' => "$path/pr2rocky.png", 'foreground' => '#ff0000');
  case 16:
    // PR2 menu picture
    return array('type' => 1, 'image' => "$path/pr2_menu.png", 'foreground' => '#000000');
  case 17:
    // PR2 plains
    return array('type' => 1, 'image' => "$path/pr2plain.png", 'foreground' => '#000000');
  case 18:
    // random
    return get_background(mt_rand(0, 17));
  default:
    return get_background(0);
  }
}
 
function fetch_cookie ($varname) {
  // fetches a cookie value, and makes the code more readable
  return $_COOKIE["chat_" . $varname];
}
 
function push_value ($varname, $value) {
  /* stores a cookie, with expiration date in 29,030,400 seconds,
     and all proper parameters                                   */ 
  setcookie("chat_" . $varname, $value, time() + 29030400, "/", ".acidch.at");
}
 
function retrieve_value ($varname, $default) {
  /* attempts to retrieve a certain value, first from the submitted values
     and/or URL, and then from the cookies                                 */
  @$tempval = $_REQUEST[$varname];
  if (!isset($tempval)) @$tempval = fetch_cookie($varname);
  if (isset($tempval)) return $tempval; else return $default;
}
 
function get_value ($varname, $limit, $default) {
  /* gets a value (by calling retrieve_value(), and checks it against a
     limit. If the value is a nonnegative integer smaller than the limit,
     it keeps it. If it fails to meet this conditions (or if there isn't
     any value at all to retrieve), it uses the default instead. Whichever
     it chooses, it stores it in a cookie.                                 */
  $tempval = retrieve_value($varname, $default);
  $numval = intval($tempval);
  if ($numval < 0 or $numval >= $limit) $numval = $default;
  push_value($varname, $numval);
  return $numval;
}
 
function get_parameters () {
  $current_tag = 1;
  $params = array(
    'chatmode' => get_value('chat', 18, 0),
    'game' => get_value('game', 2, 1),
    'background' => get_value('bg', 19, 0),
    'announcements' => get_value('announce', 2, 1)
  );
  if (get_value('tag', 1000, 0) != $current_tag) {
    push_value('chatmode', 0);
    push_value('game', 1);
    push_value('background', 0);
    push_value('announcements', 1);
    push_value('tag', $current_tag);
    return array(
      'chatmode' => 0,
      'game' => 1,
      'background' => 0,
      'announcements' => 1
    );
  }
  return $params;
}
 
function get_cell_info ($params) {
  $cells = array();
  $count = 0;
  $chat = get_chat($params['chatmode']);
  $game = get_game($params['game']);
  if ($game !== null) {
    $game['number'] = (string) (++ $count);
    $cells[$count] = $game;
  }
  if ($chat !== null) {
    $chat['number'] = (string) (++ $count);
    $cells[$count] = $chat;
  }
  if ($count == 0) return false;
  $cells[0] = $count;
  return $cells;
}
 
function get_announcebox_info ($params) {
  return ($params['announcements']) ? array(1 => get_announcebox_URI()) : false;
}
 
function get_button_info () {
  return array(
    0 => 3,
    1 => array(
      'name' => 'forums',
      'link' => '/forums.htm'
    ),
    2 => array(
      'name' => 'rules',
      'link' => '/showfile.php?file=ruletext.txt'
    ),
    3 => array(
      'name' => 'hosts',
      'link' => '/staff.htm'
    )
  );
}
 
function get_table_info ($cellinfo) {
  if ($cellinfo === false) return false;
  return array(1 => (string) $cellinfo[0]);
}
 
function get_form_info () {
  return array(
    'action' => $_SERVER['PHP_SELF'],
    'method' => 'get'
  );
}
 
function get_selector_info () {
  return array(
    0 => 4,
    1 => array(
      'displayName' => 'Chat mode',
      'internalName' => 'chat'
    ),
    2 => array(
      'displayName' => 'Announcements',
      'internalName' => 'announce'
    ),
    3 => array(
      'displayName' => 'Game',
      'internalName' => 'game'
    ),
    4 => array(
      'displayName' => 'Background',
      'internalName' => 'bg'
    )
  );
}
 
function get_page_info ($location) {
  return array(
    'pageTitle' => 'Acid Chat',
    'filePath' => $location,
    'acidlogo' => '/logos/0.png'
  );
}
 
function get_options_info ($params, $selector) {
  switch ($selector) {
  case 1:
    $data = array(
      0 => 18,
      1 => array(
        'name' => 'lightIRC default',
        'value' => '0',
        'selected' => ''
      ),
      2 => array(
        'name' => 'lightIRC black',
        'value' => '1',
        'selected' => ''
      ),
      3 => array(
        'name' => 'lightIRC blue',
        'value' => '2',
        'selected' => ''
      ),
      4 => array(
        'name' => 'lightIRC dark orange',
        'value' => '3',
        'selected' => ''
      ),
      5 => array(
        'name' => 'lightIRC green',
        'value' => '4',
        'selected' => ''
      ),
      6 => array(
        'name' => 'lightIRC light blue',
        'value' => '5',
        'selected' => ''
      ),
      7 => array(
        'name' => 'lightIRC yellow',
        'value' => '6',
        'selected' => ''
      ),
      8 => array(
        'name' => 'lightIRC random',
        'value' => '7',
        'selected' => ''
      ),
      9 => array(
        'name' => 'Eris (default)',
        'value' => '8',
        'selected' => ''
      ),
      10 => array(
        'name' => 'Eris (blue)',
        'value' => '9',
        'selected' => ''
      ),
      11 => array(
        'name' => 'Eris (gray)',
        'value' => '10',
        'selected' => ''
      ),
      12 => array(
        'name' => 'Eris (light blue)',
        'value' => '11',
        'selected' => ''
      ),
      13 => array(
        'name' => 'Eris (wood)',
        'value' => '12',
        'selected' => ''
      ),
      14 => array(
        'name' => 'Eris (pink)',
        'value' => '13',
        'selected' => ''
      ),
      15 => array(
        'name' => 'Eris (random)',
        'value' => '14',
        'selected' => ''
      ),
      16 => array(
        'name' => 'Any random IRC',
        'value' => '15',
        'selected' => ''
      ),
      17 => array(
        'name' => 'Backup (Chatango)',
        'value' => '16',
        'selected' => ''
      ),
      18 => array(
        'name' => 'None',
        'value' => '17',
        'selected' => ''
      )
    );
    $data[1 + $params['chatmode']]['selected'] = 'selected';
    return $data;
  case 2:
    $data = array(
      0 => 2,
      1 => array(
        'name' => 'Hide',
        'value' => '0',
        'selected' => ''
      ),
      2 => array(
        'name' => 'Show',
        'value' => '1',
        'selected' => ''
      )
    );
    $data[1 + $params['announcements']]['selected'] = 'selected';
    return $data;
  case 3:
    $data = array(
      0 => 2,
      1 => array(
        'name' => 'None',
        'value' => '0',
        'selected' => ''
      ),
      2 => array(
        'name' => 'PR2',
        'value' => '1',
        'selected' => ''
      )
    );
    $data[1 + $params['game']]['selected'] = 'selected';
    return $data;
  case 4:
    $data = array(
      0 => 19,
      1 => array(
        'name' => 'Default',
        'value' => '0',
        'selected' => ''
      ),
      2 => array(
        'name' => 'Creation',
        'value' => '1',
        'selected' => ''
      ),
      3 => array(
        'name' => 'PR2 fields',
        'value' => '2',
        'selected' => ''
      ),
      4 => array(
        'name' => 'PR2 space',
        'value' => '3',
        'selected' => ''
      ),
      5 => array(
        'name' => 'Fire',
        'value' => '4',
        'selected' => ''
      ),
      6 => array(
        'name' => 'Space',
        'value' => '5',
        'selected' => ''
      ),
      7 => array(
        'name' => 'Solid (black)',
        'value' => '6',
        'selected' => ''
      ),
      8 => array(
        'name' => 'Solid (red)',
        'value' => '7',
        'selected' => ''
      ),
      9 => array(
        'name' => 'Solid (blue)',
        'value' => '8',
        'selected' => ''
      ),
      10 => array(
        'name' => 'Solid (green)',
        'value' => '9',
        'selected' => ''
      ),
      11 => array(
        'name' => 'Solid (orange)',
        'value' => '10',
        'selected' => ''
      ),
      12 => array(
        'name' => 'Space (2)',
        'value' => '11',
        'selected' => ''
      ),
      13 => array(
        'name' => 'PR3K firestone',
        'value' => '12',
        'selected' => ''
      ),
      14 => array(
        'name' => 'PR2 lobby',
        'value' => '13',
        'selected' => ''
      ),
      15 => array(
        'name' => 'PR2 city',
        'value' => '14',
        'selected' => ''
      ),
      16 => array(
        'name' => 'PR2 rocky field',
        'value' => '15',
        'selected' => ''
      ),
      17 => array(
        'name' => 'PR2 menu picture',
        'value' => '16',
        'selected' => ''
      ),
      18 => array(
        'name' => 'PR2 plains',
        'value' => '17',
        'selected' => ''
      ),
      19 => array(
        'name' => 'Random',
        'value' => '18',
        'selected' => ''
      )
    );
    $data[1 + $params['background']]['selected'] = 'selected';
    return $data;
  default:
    return false;
  }
}
 
function next_option_set ($params, $counter) {
  $curr = (++ $counter -> value);
  $data = get_options_info($params, $curr);
  if ($data === false) {
    $counter -> value = 1;
    $data = get_options_info($params, 1);
  }
  return $data;
}
 
class Wrapper {
  public $value;
  function __construct ($val) {
    $this -> value = $val;
  }
}
 
function get_background_image ($p, $c, $i, $l, $data) {
  if ($data['type'] == 1)
    return array('image' => $data['image'], 'forecolor' => $data['foreground']);
  else
    return false;
}
 
function get_background_color ($p, $c, $i, $l, $data) {
  if ($data['type'] == 0)
    return array('backcolor' => $data['background'], 'forecolor' => $data['foreground']);
  else
    return false;
}
 
function generate_page ($templateData, $filepath) {
  $params = get_parameters();
  $cells = get_cell_info($params);
  $bgdata = get_background($params['background']);
  $currentOption = new Wrapper(0);
  $callbacks = array(
    'announcements' => 'get_announcebox_info',
    'background_image' => 'get_background_image',
    'background_solid' => 'get_background_color',
    'button' => 'get_button_info',
    'cell' => function ($p, $c, $i) {return $i;},
    'form' => 'get_form_info',
    'option' => 'next_option_set',
    'page' => function ($p, $c, $i, $l) {return get_page_info($l);},
    'select' => 'get_selector_info',
    'table' => function ($p, $c, $i) {return get_table_info($i);}
  );
  return parse_template((string) $templateData, $callbacks, $params, $currentOption, $cells, $filepath, $bgdata);
}
 
?>

Comments