Advertisement
aaaaaa123456789

Acid Chat template processing code

Feb 18th, 2013
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.82 KB | None | 0 0
  1. <?php
  2.  
  3. include "ptempl.php";
  4.  
  5. function get_PR2code () {
  6.   // returns the PR2 embed code
  7.   $code = '<embed width="550" height="400" base="http://external.kongregate-games.com/gamez/0001/0110/live/"
  8.  
  9. src="http://external.kongregate-games.com/gamez/0001/0110/live/embeddable_10110.swf" type="application/x-shockwave-flash"></embed>';
  10.   return array('width' => '550', 'height' => '400', 'contents' => $code);
  11. }
  12.  
  13. function get_announcebox_URI () {
  14.   return 'http://acidchat.comuf.com/announce.php';
  15. }
  16.  
  17. function get_backchat() {
  18.   // returns the backup chat embed code
  19.   $code = '<object width="400" height="400" id="obj_1313089480453"><param name="movie" value="http://acidbackup.chatango.com/group"/><param
  20.  
  21. name="wmode" value="transparent"/><param name="AllowScriptAccess" VALUE="always"/><param name="AllowNetworking" VALUE="all"/><param
  22.  
  23. name="AllowFullScreen" VALUE="true"/><param name="flashvars" value="cid=1313089480453&b=60&f=50&l=999999&q=999999&r=100&s=1"/><embed
  24.  
  25. id="emb_1313089480453" src="http://acidbackup.chatango.com/group" width="400" height="400" wmode="transparent" allowScriptAccess="always"
  26.  
  27. allowNetworking="all" type="application/x-shockwave-flash" allowFullScreen="true"
  28.  
  29. flashvars="cid=1313089480453&b=60&f=50&l=999999&q=999999&r=100&s=1"></embed></object>';
  30.   return array('width' => '400', 'height' => '400', 'contents' => $code);
  31. }
  32.  
  33. function get_lightIRC ($style) {
  34.   switch ($style) {
  35.   case 'black':
  36.     $page = 'black';
  37.     break;
  38.   case 'blue':
  39.     $page = 'blue';
  40.     break;
  41.   case 'darkorange':
  42.     $page = 'do';
  43.     break;
  44.   case 'green':
  45.     $page = 'green';
  46.     break;
  47.   case 'lightblue':
  48.     $page = 'litblue';
  49.     break;
  50.   case 'yellow':
  51.     $page = 'yellow';
  52.     break;
  53.   case 'default': default:
  54.     $page = 'index';
  55.   }
  56.   $code = '<iframe src="http://acidch.at/clients/lightIRC/' . $page . '.html" style="width:550px; height:400px;">Sorry, if this shows up, you have
  57.  
  58. to update your browser.</iframe>';
  59.   return array('width' => '550', 'height' => '400', 'contents' => $code);
  60. }
  61.  
  62. function get_eris($mode) {
  63.   $code = '<iframe src="http://acidch.at/clients/eris_' . $mode . '" width=550 height=400 frameborder=0 border=0 scrolling=no scrollbar=no>Sorry!
  64.  
  65. You need to update your browser to use the chat.</iframe>';
  66.   return array('width' => '550', 'height' => '400', 'contents' => $code);
  67. }
  68.  
  69. function get_chat_lightIRC ($pagemode) {
  70.   // returns the code for the chat, on the new client, lightIRC
  71.   switch ($pagemode) {
  72.   case 1:
  73.     return get_lightIRC('black');
  74.   case 2:
  75.     return get_lightIRC('blue');
  76.   case 3:
  77.     return get_lightIRC('darkorange');
  78.   case 4:
  79.     return get_lightIRC('green');
  80.   case 5:
  81.     return get_lightIRC('lightblue');
  82.   case 6:
  83.     return get_lightIRC('yellow');
  84.   case 7:
  85.     return get_chat_lightIRC(mt_rand(0, 6));
  86.   case 0: default:
  87.     return get_lightIRC('default');
  88.   }
  89. }
  90.  
  91. function get_chat_eris ($pagemode) {
  92.   // returns the code for the chat, on the client Eris
  93.   switch ($pagemode) {
  94.   case 8:
  95.     return get_eris('dfl'); // default
  96.   case 9:
  97.     return get_eris('blu'); // blue
  98.   case 10:
  99.     return get_eris('gry'); // gray
  100.   case 11:
  101.     return get_eris('lb'); // light blue
  102.   case 12:
  103.     return get_eris('wod'); // wood
  104.   case 13:
  105.     return get_eris('pnk'); // pink
  106.   case 14:
  107.     return get_chat_eris(8 + mt_rand(0, 5));
  108.   default:
  109.     return get_chat_eris(8);
  110.   }
  111. }
  112.  
  113. function get_chat ($pagemode) {
  114.   /* selects an IRC client for embedding */
  115.   if ($pagemode >= 0 && $pagemode <= 7) return get_chat_lightIRC($pagemode);
  116.   if ($pagemode >= 8 && $pagemode <= 14) return get_chat_eris($pagemode);
  117.   if ($pagemode == 15) return get_chat(mt_rand(0, 14));
  118.   if ($pagemode == 16) return get_backchat();
  119.   if ($pagemode == 17) return null;
  120.   return get_chat_lightIRC(0);
  121. }
  122.  
  123. function get_game ($val) {
  124.   // returns the code for the selected value for Game
  125.   switch ($val) {
  126.   case 1:
  127.     return get_PR2code();
  128.   case 0: default:
  129.     return null;
  130.   }
  131. }
  132.  
  133. function get_background ($bgnumber) {
  134.   $path = '/backgrnd';
  135.   switch ($bgnumber) {
  136.   case 0:
  137.     // default
  138.     return array('type' => 1, 'image' => "$path/bg_dflt.gif", 'foreground' => '#ffffff');
  139.   case 1:
  140.     // creation
  141.     return array('type' => 1, 'image' => "$path/bg_crtn.jpg", 'foreground' => '#000000');
  142.   case 2:
  143.     // pr2 fields
  144.     return array('type' => 1, 'image' => "$path/bg_pr2fd.png", 'foreground' => '#000000');
  145.   case 3:
  146.     // pr2 space
  147.     return array('type' => 1, 'image' => "$path/bg_pr2sp.png", 'foreground' => '#ff0000');
  148.   case 4:
  149.     // fire
  150.     return array('type' => 1, 'image' => "$path/bg_fire.png", 'foreground' => '#000000');
  151.   case 5:
  152.     // space
  153.     return array('type' => 1, 'image' => "$path/bg_space.jpg", 'foreground' => '#000000');
  154.   case 6:
  155.     // black
  156.     return array('type' => 0, 'background' => '#000000', 'foreground' => '#ffffff');
  157.   case 7:
  158.     // dark red
  159.     return array('type' => 0, 'background' => '#800000', 'foreground' => '#ffffff');
  160.   case 8:
  161.     // dark blue
  162.     return array('type' => 0, 'background' => '#000080', 'foreground' => '#ffffff');
  163.   case 9:
  164.     // dark green
  165.     return array('type' => 0, 'background' => '#005000', 'foreground' => '#ffffff');
  166.   case 10:
  167.     // dark orange
  168.     return array('type' => 0, 'background' => '#bf590e', 'foreground' => '#ffffff');
  169.   case 11:
  170.     // space 2
  171.     return array('type' => 1, 'image' => "$path/bg_spac2.gif", 'foreground' => '#ffffff');
  172.   case 12:
  173.     // PR3K firestone
  174.     return array('type' => 1, 'image' => "$path/bg_3k_fs.jpg", 'foreground' => '#ffffff');
  175.   case 13:
  176.     // PR2 lobby
  177.     return array('type' => 1, 'image' => "$path/pr2lobby.png", 'foreground' => '#000000');
  178.   case 14:
  179.     // PR2 city
  180.     return array('type' => 1, 'image' => "$path/pr2_city.png", 'foreground' => '#ffffff');
  181.   case 15:
  182.     // PR2 rocky field
  183.     return array('type' => 1, 'image' => "$path/pr2rocky.png", 'foreground' => '#ff0000');
  184.   case 16:
  185.     // PR2 menu picture
  186.     return array('type' => 1, 'image' => "$path/pr2_menu.png", 'foreground' => '#000000');
  187.   case 17:
  188.     // PR2 plains
  189.     return array('type' => 1, 'image' => "$path/pr2plain.png", 'foreground' => '#000000');
  190.   case 18:
  191.     // random
  192.     return get_background(mt_rand(0, 17));
  193.   default:
  194.     return get_background(0);
  195.   }
  196. }
  197.  
  198. function fetch_cookie ($varname) {
  199.   // fetches a cookie value, and makes the code more readable
  200.   return $_COOKIE["chat_" . $varname];
  201. }
  202.  
  203. function push_value ($varname, $value) {
  204.   /* stores a cookie, with expiration date in 29,030,400 seconds,
  205.      and all proper parameters                                   */
  206.   setcookie("chat_" . $varname, $value, time() + 29030400, "/", ".acidch.at");
  207. }
  208.  
  209. function retrieve_value ($varname, $default) {
  210.   /* attempts to retrieve a certain value, first from the submitted values
  211.      and/or URL, and then from the cookies                                 */
  212.   @$tempval = $_REQUEST[$varname];
  213.   if (!isset($tempval)) @$tempval = fetch_cookie($varname);
  214.   if (isset($tempval)) return $tempval; else return $default;
  215. }
  216.  
  217. function get_value ($varname, $limit, $default) {
  218.   /* gets a value (by calling retrieve_value(), and checks it against a
  219.      limit. If the value is a nonnegative integer smaller than the limit,
  220.      it keeps it. If it fails to meet this conditions (or if there isn't
  221.      any value at all to retrieve), it uses the default instead. Whichever
  222.      it chooses, it stores it in a cookie.                                 */
  223.   $tempval = retrieve_value($varname, $default);
  224.   $numval = intval($tempval);
  225.   if ($numval < 0 or $numval >= $limit) $numval = $default;
  226.   push_value($varname, $numval);
  227.   return $numval;
  228. }
  229.  
  230. function get_parameters () {
  231.   $current_tag = 1;
  232.   $params = array(
  233.     'chatmode' => get_value('chat', 18, 0),
  234.     'game' => get_value('game', 2, 1),
  235.     'background' => get_value('bg', 19, 0),
  236.     'announcements' => get_value('announce', 2, 1)
  237.   );
  238.   if (get_value('tag', 1000, 0) != $current_tag) {
  239.     push_value('chatmode', 0);
  240.     push_value('game', 1);
  241.     push_value('background', 0);
  242.     push_value('announcements', 1);
  243.     push_value('tag', $current_tag);
  244.     return array(
  245.       'chatmode' => 0,
  246.       'game' => 1,
  247.       'background' => 0,
  248.       'announcements' => 1
  249.     );
  250.   }
  251.   return $params;
  252. }
  253.  
  254. function get_cell_info ($params) {
  255.   $cells = array();
  256.   $count = 0;
  257.   $chat = get_chat($params['chatmode']);
  258.   $game = get_game($params['game']);
  259.   if ($game !== null) {
  260.     $game['number'] = (string) (++ $count);
  261.     $cells[$count] = $game;
  262.   }
  263.   if ($chat !== null) {
  264.     $chat['number'] = (string) (++ $count);
  265.     $cells[$count] = $chat;
  266.   }
  267.   if ($count == 0) return false;
  268.   $cells[0] = $count;
  269.   return $cells;
  270. }
  271.  
  272. function get_announcebox_info ($params) {
  273.   return ($params['announcements']) ? array(1 => get_announcebox_URI()) : false;
  274. }
  275.  
  276. function get_button_info () {
  277.   return array(
  278.     0 => 3,
  279.     1 => array(
  280.       'name' => 'forums',
  281.       'link' => '/forums.htm'
  282.     ),
  283.     2 => array(
  284.       'name' => 'rules',
  285.       'link' => '/showfile.php?file=ruletext.txt'
  286.     ),
  287.     3 => array(
  288.       'name' => 'hosts',
  289.       'link' => '/staff.htm'
  290.     )
  291.   );
  292. }
  293.  
  294. function get_table_info ($cellinfo) {
  295.   if ($cellinfo === false) return false;
  296.   return array(1 => (string) $cellinfo[0]);
  297. }
  298.  
  299. function get_form_info () {
  300.   return array(
  301.     'action' => $_SERVER['PHP_SELF'],
  302.     'method' => 'get'
  303.   );
  304. }
  305.  
  306. function get_selector_info () {
  307.   return array(
  308.     0 => 4,
  309.     1 => array(
  310.       'displayName' => 'Chat mode',
  311.       'internalName' => 'chat'
  312.     ),
  313.     2 => array(
  314.       'displayName' => 'Announcements',
  315.       'internalName' => 'announce'
  316.     ),
  317.     3 => array(
  318.       'displayName' => 'Game',
  319.       'internalName' => 'game'
  320.     ),
  321.     4 => array(
  322.       'displayName' => 'Background',
  323.       'internalName' => 'bg'
  324.     )
  325.   );
  326. }
  327.  
  328. function get_page_info ($location) {
  329.   return array(
  330.     'pageTitle' => 'Acid Chat',
  331.     'filePath' => $location,
  332.     'acidlogo' => '/logos/0.png'
  333.   );
  334. }
  335.  
  336. function get_options_info ($params, $selector) {
  337.   switch ($selector) {
  338.   case 1:
  339.     $data = array(
  340.       0 => 18,
  341.       1 => array(
  342.         'name' => 'lightIRC default',
  343.         'value' => '0',
  344.         'selected' => ''
  345.       ),
  346.       2 => array(
  347.         'name' => 'lightIRC black',
  348.         'value' => '1',
  349.         'selected' => ''
  350.       ),
  351.       3 => array(
  352.         'name' => 'lightIRC blue',
  353.         'value' => '2',
  354.         'selected' => ''
  355.       ),
  356.       4 => array(
  357.         'name' => 'lightIRC dark orange',
  358.         'value' => '3',
  359.         'selected' => ''
  360.       ),
  361.       5 => array(
  362.         'name' => 'lightIRC green',
  363.         'value' => '4',
  364.         'selected' => ''
  365.       ),
  366.       6 => array(
  367.         'name' => 'lightIRC light blue',
  368.         'value' => '5',
  369.         'selected' => ''
  370.       ),
  371.       7 => array(
  372.         'name' => 'lightIRC yellow',
  373.         'value' => '6',
  374.         'selected' => ''
  375.       ),
  376.       8 => array(
  377.         'name' => 'lightIRC random',
  378.         'value' => '7',
  379.         'selected' => ''
  380.       ),
  381.       9 => array(
  382.         'name' => 'Eris (default)',
  383.         'value' => '8',
  384.         'selected' => ''
  385.       ),
  386.       10 => array(
  387.         'name' => 'Eris (blue)',
  388.         'value' => '9',
  389.         'selected' => ''
  390.       ),
  391.       11 => array(
  392.         'name' => 'Eris (gray)',
  393.         'value' => '10',
  394.         'selected' => ''
  395.       ),
  396.       12 => array(
  397.         'name' => 'Eris (light blue)',
  398.         'value' => '11',
  399.         'selected' => ''
  400.       ),
  401.       13 => array(
  402.         'name' => 'Eris (wood)',
  403.         'value' => '12',
  404.         'selected' => ''
  405.       ),
  406.       14 => array(
  407.         'name' => 'Eris (pink)',
  408.         'value' => '13',
  409.         'selected' => ''
  410.       ),
  411.       15 => array(
  412.         'name' => 'Eris (random)',
  413.         'value' => '14',
  414.         'selected' => ''
  415.       ),
  416.       16 => array(
  417.         'name' => 'Any random IRC',
  418.         'value' => '15',
  419.         'selected' => ''
  420.       ),
  421.       17 => array(
  422.         'name' => 'Backup (Chatango)',
  423.         'value' => '16',
  424.         'selected' => ''
  425.       ),
  426.       18 => array(
  427.         'name' => 'None',
  428.         'value' => '17',
  429.         'selected' => ''
  430.       )
  431.     );
  432.     $data[1 + $params['chatmode']]['selected'] = 'selected';
  433.     return $data;
  434.   case 2:
  435.     $data = array(
  436.       0 => 2,
  437.       1 => array(
  438.         'name' => 'Hide',
  439.         'value' => '0',
  440.         'selected' => ''
  441.       ),
  442.       2 => array(
  443.         'name' => 'Show',
  444.         'value' => '1',
  445.         'selected' => ''
  446.       )
  447.     );
  448.     $data[1 + $params['announcements']]['selected'] = 'selected';
  449.     return $data;
  450.   case 3:
  451.     $data = array(
  452.       0 => 2,
  453.       1 => array(
  454.         'name' => 'None',
  455.         'value' => '0',
  456.         'selected' => ''
  457.       ),
  458.       2 => array(
  459.         'name' => 'PR2',
  460.         'value' => '1',
  461.         'selected' => ''
  462.       )
  463.     );
  464.     $data[1 + $params['game']]['selected'] = 'selected';
  465.     return $data;
  466.   case 4:
  467.     $data = array(
  468.       0 => 19,
  469.       1 => array(
  470.         'name' => 'Default',
  471.         'value' => '0',
  472.         'selected' => ''
  473.       ),
  474.       2 => array(
  475.         'name' => 'Creation',
  476.         'value' => '1',
  477.         'selected' => ''
  478.       ),
  479.       3 => array(
  480.         'name' => 'PR2 fields',
  481.         'value' => '2',
  482.         'selected' => ''
  483.       ),
  484.       4 => array(
  485.         'name' => 'PR2 space',
  486.         'value' => '3',
  487.         'selected' => ''
  488.       ),
  489.       5 => array(
  490.         'name' => 'Fire',
  491.         'value' => '4',
  492.         'selected' => ''
  493.       ),
  494.       6 => array(
  495.         'name' => 'Space',
  496.         'value' => '5',
  497.         'selected' => ''
  498.       ),
  499.       7 => array(
  500.         'name' => 'Solid (black)',
  501.         'value' => '6',
  502.         'selected' => ''
  503.       ),
  504.       8 => array(
  505.         'name' => 'Solid (red)',
  506.         'value' => '7',
  507.         'selected' => ''
  508.       ),
  509.       9 => array(
  510.         'name' => 'Solid (blue)',
  511.         'value' => '8',
  512.         'selected' => ''
  513.       ),
  514.       10 => array(
  515.         'name' => 'Solid (green)',
  516.         'value' => '9',
  517.         'selected' => ''
  518.       ),
  519.       11 => array(
  520.         'name' => 'Solid (orange)',
  521.         'value' => '10',
  522.         'selected' => ''
  523.       ),
  524.       12 => array(
  525.         'name' => 'Space (2)',
  526.         'value' => '11',
  527.         'selected' => ''
  528.       ),
  529.       13 => array(
  530.         'name' => 'PR3K firestone',
  531.         'value' => '12',
  532.         'selected' => ''
  533.       ),
  534.       14 => array(
  535.         'name' => 'PR2 lobby',
  536.         'value' => '13',
  537.         'selected' => ''
  538.       ),
  539.       15 => array(
  540.         'name' => 'PR2 city',
  541.         'value' => '14',
  542.         'selected' => ''
  543.       ),
  544.       16 => array(
  545.         'name' => 'PR2 rocky field',
  546.         'value' => '15',
  547.         'selected' => ''
  548.       ),
  549.       17 => array(
  550.         'name' => 'PR2 menu picture',
  551.         'value' => '16',
  552.         'selected' => ''
  553.       ),
  554.       18 => array(
  555.         'name' => 'PR2 plains',
  556.         'value' => '17',
  557.         'selected' => ''
  558.       ),
  559.       19 => array(
  560.         'name' => 'Random',
  561.         'value' => '18',
  562.         'selected' => ''
  563.       )
  564.     );
  565.     $data[1 + $params['background']]['selected'] = 'selected';
  566.     return $data;
  567.   default:
  568.     return false;
  569.   }
  570. }
  571.  
  572. function next_option_set ($params, $counter) {
  573.   $curr = (++ $counter -> value);
  574.   $data = get_options_info($params, $curr);
  575.   if ($data === false) {
  576.     $counter -> value = 1;
  577.     $data = get_options_info($params, 1);
  578.   }
  579.   return $data;
  580. }
  581.  
  582. class Wrapper {
  583.   public $value;
  584.   function __construct ($val) {
  585.     $this -> value = $val;
  586.   }
  587. }
  588.  
  589. function get_background_image ($p, $c, $i, $l, $data) {
  590.   if ($data['type'] == 1)
  591.     return array('image' => $data['image'], 'forecolor' => $data['foreground']);
  592.   else
  593.     return false;
  594. }
  595.  
  596. function get_background_color ($p, $c, $i, $l, $data) {
  597.   if ($data['type'] == 0)
  598.     return array('backcolor' => $data['background'], 'forecolor' => $data['foreground']);
  599.   else
  600.     return false;
  601. }
  602.  
  603. function generate_page ($templateData, $filepath) {
  604.   $params = get_parameters();
  605.   $cells = get_cell_info($params);
  606.   $bgdata = get_background($params['background']);
  607.   $currentOption = new Wrapper(0);
  608.   $callbacks = array(
  609.     'announcements' => 'get_announcebox_info',
  610.     'background_image' => 'get_background_image',
  611.     'background_solid' => 'get_background_color',
  612.     'button' => 'get_button_info',
  613.     'cell' => function ($p, $c, $i) {return $i;},
  614.     'form' => 'get_form_info',
  615.     'option' => 'next_option_set',
  616.     'page' => function ($p, $c, $i, $l) {return get_page_info($l);},
  617.     'select' => 'get_selector_info',
  618.     'table' => function ($p, $c, $i) {return get_table_info($i);}
  619.   );
  620.   return parse_template((string) $templateData, $callbacks, $params, $currentOption, $cells, $filepath, $bgdata);
  621. }
  622.  
  623. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement