Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Super-session-magic-thing
- session_start();
- if (!isset($_SESSION['inventory']))
- {
- $_SESSION['inventory'] = array();
- }
- asort($_SESSION['inventory']);
- if (!isset($_SESSION['visited']))
- {
- $_SESSION['visited'] = array();
- }
- if ( !isset($_SESSION['cash']) )
- {
- $_SESSION['cash'] = 0;
- }
- if ( !isset($_SESSION['score']) )
- {
- $_SESSION['score'] = 0;
- }
- if (isset($_GET['say']))
- {
- $sayid = $_GET['say'];
- }
- else
- {
- $sayid = '0';
- }
- $talklist = array();
- $showinputbox = false;
- $headerextra = '<style type="text/css">
- div.textadventure
- {
- background-color: #333333;
- color: #ffffff;
- font-family: monospace;
- padding: 8px;
- }
- div.textadventure a
- {
- color: #ffffff;
- text-decoration: none;
- }
- div.textadventure a:hover
- {
- color: #333333;
- background-color: #ffffff;
- text-decoration: none;
- }
- </style>';
- require("header.php");
- echo '<div class="main">';
- textSectionStart();
- echo '<h2>Wikiventure (Naff Working Title)</h2>';
- if ( !isset($_GET['p']) )
- {
- $page = 'Index';
- }
- else
- {
- $page = $_GET['p'];
- }
- $curlUrl = 'http://www.minild12.sophiehoulden.com/api.php?action=query&format=xml&titles=Adventure/'.$page.'&prop=revisions&rvprop=content&list=allimages';
- // create curl resource
- $ch = curl_init();
- // set url
- curl_setopt($ch, CURLOPT_URL, $curlUrl);
- //return the transfer as a string
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- // $output contains the output string
- $curlstring = curl_exec($ch);
- $xml = new SimpleXMLElement($curlstring);
- // close curl resource to free up system resources
- curl_close($ch);
- //print_r($xml);
- if( !(bool)$xml->query->pages->page['pageid'] )
- {
- echo '<div class="textadventure">
- <b>Oops! Page does not exist!</b><br/>
- If you like, you can create it <a href="http://www.minild12.sophiehoulden.com/index.php?title=Adventure/'.$page.'&action=edit">here.</a>
- </div>';
- }
- else
- {
- $output = $xml->query->pages->page->revisions->rev;
- $useitem = '';
- if (isset($_GET['get']))
- {
- if ( !in_array( $_GET['get'], $_SESSION['inventory'] ) )
- {
- $output = 'You pick-up the '.$_GET['get'].'.<br/><br/>' . $output;
- $_SESSION['inventory'][] = $_GET['get'];
- }
- }
- elseif (isset($_GET['use']))
- {
- if ( in_array( $_GET['use'], $_SESSION['inventory'] ) )
- {
- $output = 'You use your '.$_GET['use'].'.<br/><br/>' . $output;
- $useitem = $_GET['use'];
- }
- }
- //Location link repolacements
- $link_before = array('[[Adventure/', '|', ']]');
- $link_after = array('> <a href="minild12.php?p=', '">', '</a>');
- $offset = 0;
- $linkslist = array();
- while ( substr_count( $output, '[[') > 0 )
- {
- $startpos = strpos($output, '[[');
- $endpos = strpos($output, ']]', $startpos);
- $midpos = strpos($output, ':', $startpos);
- //Make-sure it gets the correct ]]
- $obcount = substr_count($output, '[[', $startpos+2, $endpos-$startpos-2);
- for ( $i = 0; $i < $obcount; $i++ )
- {
- $temppos = $endpos;
- $endpos = strpos( $output, ']]', $endpos+2 );
- $i -= ( substr_count( substr($output,$temppos,$endpos-$temppos), '[[') );
- }
- if ( ($midpos >= $endpos) || ($midpos <= $startpos) ) //No : in it
- {
- $temp = substr( $output, $startpos, $endpos - $startpos + 2);
- $linkslist[] = str_replace( $link_before, $link_after, $temp );
- $output = substr_replace( $output, '', $startpos, $endpos - $startpos + 2 );
- }
- else //Otherwise, parse the code!
- {
- $secondhalf = substr($output, $midpos+1, $endpos-$midpos-1);
- switch( substr( $output, $startpos+2, $midpos - $startpos -2) )
- {
- //SHOW IMAGE
- case 'File':
- foreach ($xml->query->allimages->img as $img)
- {
- if ( $img['name'] == $secondhalf )
- {
- $imageurl = $img['url'];
- }
- }
- $output = str_replace("[[File:$secondhalf]]", "<img src='$imageurl'/>",$output);
- break;
- //GET ITEM
- case 'GET':
- $output = str_replace("[[GET:$secondhalf]]", '',$output);
- if ( !in_array($secondhalf, $_SESSION['inventory']) )
- {
- $itemshere[] = "$secondhalf";
- }
- break;
- case 'IFHAVE':
- $splitpos = strpos($secondhalf, '|');
- $itemname = substr($secondhalf, 0, $splitpos);
- $haveitemtext = substr($secondhalf, $splitpos+1);
- if ( in_array($itemname, $_SESSION['inventory']) )
- {
- $output = substr_replace( $output, $haveitemtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'IFNHAVE':
- $splitpos = strpos($secondhalf, '|');
- $itemname = substr($secondhalf, 0, $splitpos);
- $haveitemtext = substr($secondhalf, $splitpos+1);
- if ( !in_array($itemname, $_SESSION['inventory']) )
- {
- $output = substr_replace( $output, $haveitemtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'LOSE':
- if ( $secondhalf == '*ALL' )
- {
- $output = substr_replace( $output, 'You lose all your items!', $startpos, $endpos-$startpos+2);
- unset($_SESSION['inventory']);
- $_SESSION['inventory'] = array();
- }
- elseif ( in_array($secondhalf, $_SESSION['inventory']) )
- {
- $output = substr_replace( $output, 'You lose your ' . $secondhalf, $startpos, $endpos-$startpos+2);
- unset($_SESSION['inventory'][array_search($secondhalf,$_SESSION['inventory'])]);
- $_SESSION['inventory'] = array_values($_SESSION['inventory']);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'USE':
- $splitpos = strpos($secondhalf, '|');
- if ( $splitpos != 0 )
- {
- $itemname = substr($secondhalf, 0, $splitpos);
- $useitemtext = substr($secondhalf, $splitpos+1);
- }
- else
- {
- $itemname = $secondhalf;
- $useitemtext = '';
- }
- if ( $useitem == $itemname )
- {
- $output = substr_replace( $output, $useitemtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'NUSE':
- $splitpos = strpos($secondhalf, '|');
- if ( $splitpos != 0 )
- {
- $itemname = substr($secondhalf, 0, $splitpos);
- $useitemtext = substr($secondhalf, $splitpos+1);
- }
- else
- {
- $itemname = $secondhalf;
- $useitemtext = '';
- }
- if ( $useitem != $itemname )
- {
- $output = substr_replace( $output, $useitemtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- //VISITING
- case 'IFVISITED':
- $splitpos = strpos($secondhalf, '|');
- $placename = substr($secondhalf, 0, $splitpos);
- if ( trim($placename) == '' ) { $placename = $page; }
- $visitedtext = substr($secondhalf, $splitpos+1);
- if ( in_array($placename, $_SESSION['visited']) )
- {
- $output = substr_replace( $output, $visitedtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'IFNVISITED':
- $splitpos = strpos($secondhalf, '|');
- $placename = substr($secondhalf, 0, $splitpos);
- if ( trim($placename) == '' ) { $placename = $page; }
- $visitedtext = substr($secondhalf, $splitpos+1);
- if ( !in_array($placename, $_SESSION['visited']) )
- {
- $output = substr_replace( $output, $visitedtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- //CONVERSATIONS
- case 'SPEECH':
- $splitpos = strpos($secondhalf, '|');
- $speechid = substr($secondhalf, 0, $splitpos);
- $speechtext = substr($secondhalf, $splitpos+1);
- if ( (int)$sayid == (int)$speechid )
- {
- $output = substr_replace( $output, $speechtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'TALK':
- $commapos = strpos($secondhalf, ',');
- $splitpos = strpos($secondhalf, '|');
- $talkid = substr($secondhalf, 0, $commapos); //The id of speech to show
- $speechid = substr($secondhalf, $commapos+1, $splitpos-$commapos-1);//The speech id to display this
- $speechtext = substr($secondhalf, $splitpos+1); //What to say
- if ( $talkid == $sayid ) //Just said this
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- $output = 'You: ' . $speechtext . '<br/><br/>' . $output;
- }
- elseif ( ($speechid == $sayid) || (trim($speechid) == '') )
- { //Display this speech option.
- $talklist[] = '> <a href="minild12.php?p='.$page.'&say='.$talkid.'">Say "'.$speechtext.'"</a>';
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- else
- {
- //Remove the tag
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- //CASH
- case 'IFCASH':
- $commapos = strpos($secondhalf, ',');
- $splitpos = strpos($secondhalf, '|');
- $cashlow = substr($secondhalf, 0, $commapos); //Cash lower bound
- $cashhigh = substr($secondhalf, $commapos+1, $splitpos-$commapos-1); //Cash upper bound
- $cashtext = substr($secondhalf, $splitpos+1); //What to say
- if ( (($_SESSION['cash'] >= (int)$cashlow) || (trim($cashlow) == '')) &&
- (($_SESSION['cash'] <= (int)$cashhigh) || (trim($cashhigh) == '')) ) //cash is between bounds
- {
- $output = substr_replace( $output, $cashtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'IFNCASH':
- $commapos = strpos($secondhalf, ',');
- $splitpos = strpos($secondhalf, '|');
- $cashlow = substr($secondhalf, 0, $commapos); //Cash lower bound
- $cashhigh = substr($secondhalf, $commapos+1, $splitpos-$commapos-1); //Cash upper bound
- $cashtext = substr($secondhalf, $splitpos+1); //What to say
- if ( (($_SESSION['cash'] < (int)$cashlow) && !(trim($cashlow) == '')) ||
- (($_SESSION['cash'] > (int)$cashhigh) && !(trim($cashhigh) == '')) ) //cash is between bounds
- {
- $output = substr_replace( $output, $cashtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'GIVECASH':
- $_SESSION['cash'] += (int)$secondhalf; //Simple as that! Hopefully.
- break;
- //SCORE
- case 'IFSCORE':
- $commapos = strpos($secondhalf, ',');
- $splitpos = strpos($secondhalf, '|');
- $cashlow = substr($secondhalf, 0, $commapos); //Cash lower bound
- $cashhigh = substr($secondhalf, $commapos+1, $splitpos-$commapos-1); //Cash upper bound
- $cashtext = substr($secondhalf, $splitpos+1); //What to say
- if ( (($_SESSION['score'] >= (int)$cashlow) || (trim($cashlow) == '')) &&
- (($_SESSION['score'] <= (int)$cashhigh) || (trim($cashhigh) == '')) ) //cash is between bounds
- {
- $output = substr_replace( $output, $cashtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'IFNSCORE':
- $commapos = strpos($secondhalf, ',');
- $splitpos = strpos($secondhalf, '|');
- $cashlow = substr($secondhalf, 0, $commapos); //Cash lower bound
- $cashhigh = substr($secondhalf, $commapos+1, $splitpos-$commapos-1); //Cash upper bound
- $cashtext = substr($secondhalf, $splitpos+1); //What to say
- if ( (($_SESSION['score'] < (int)$cashlow) && !(trim($cashlow) == '')) ||
- (($_SESSION['score'] > (int)$cashhigh) && !(trim($cashhigh) == '')) ) //cash is between bounds
- {
- $output = substr_replace( $output, $cashtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'GIVEPOINTS':
- $_SESSION['score'] += (int)$secondhalf; //Simple as that! Hopefully.
- break;
- //INPUT
- case 'IFINPUT':
- $showinputbox = true;
- $splitpos = strpos($secondhalf, '|');
- $inputexpected = substr($secondhalf, 0, $splitpos);
- $inputtext = substr($secondhalf, $splitpos+1);
- if ( strtoupper(trim($_GET['i'])) == strtoupper(trim($inputexpected)) )
- {
- $output = substr_replace( $output, $inputtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- case 'IFNINPUT':
- $showinputbox = true;
- $splitpos = strpos($secondhalf, '|');
- $inputexpected = substr($secondhalf, 0, $splitpos);
- $inputtext = substr($secondhalf, $splitpos+1);
- if ( strtoupper(trim($_GET['i'])) != strtoupper(trim($inputexpected)) )
- {
- $output = substr_replace( $output, $inputtext, $startpos, $endpos-$startpos+2);
- }
- else
- {
- $output = substr_replace( $output, '', $startpos, $endpos-$startpos+2);
- }
- break;
- //DEFAULT
- default:
- $output = substr_replace( $output, '', $startpos, $endpos - $startpos + 2 );
- }
- }
- }
- $output = str_replace( "\n", '<br/>', trim($output) );
- //Add a list of items here.
- if ( count($itemshere) != 0 )
- {
- $itemsherelist = 'You see the following items here: ';
- $firstitem = true;
- foreach ( $itemshere as $anitem )
- {
- if ( $firstitem )
- {
- $itemsherelist .= $anitem;
- $firstitem = false;
- }
- else
- {
- $itemsherelist .= ', '.$anitem;
- }
- }
- }
- $output .= '<br/><br/>';
- //Speech links
- if ( count($talklist) > 0 )
- {
- foreach ( $talklist as $anitem )
- {
- array_unshift($linkslist, '<br/>'.$anitem);
- }
- $output .= $itemsherelist . '<br/><br/>';
- }
- //Add 'get this' links
- if ( count($itemshere) > 0 )
- {
- foreach ( $itemshere as $anitem )
- {
- array_unshift($linkslist, '<br/>> <a href="minild12.php?p='.$page.'&get='.urlencode($anitem).'">'.
- 'Pick up the '.$anitem.'</a>');
- }
- $output .= $itemsherelist . '<br/><br/>';
- }
- foreach ( $linkslist as $link )
- {
- $output .= $link.'<br/>';
- }
- //Parse bold and italics
- $output = str_replace_every_other("'''", '<b>', $output);
- $output = str_replace("'''",'</b>',$output);
- $output = str_replace_every_other("''", '<i>', $output);
- $output = str_replace("''",'</i>',$output);
- //Output it!
- echo '<div class="textadventure">'.$output.'
- <br/>';
- if ( $showinputbox == true )
- {
- echo '<form action="minild12.php" method="get">
- Input something: <input type="text" name="i" /> (Press enter)
- <input type="hidden" name="p" value="'.$page.'" />
- </form>';
- }
- echo 'Inventory (Click to use): ';
- $firstitem = true;
- foreach($_SESSION['inventory'] as $invitem)
- {
- if ( $firstitem )
- {
- echo '<a href="minild12.php?p='.$page.'&use='.$invitem.'">'.$invitem.'</a>';
- $firstitem = false;
- }
- else
- {
- echo ', <a href="minild12.php?p='.$page.'&use='.$invitem.'">'.$invitem.'</a>';
- }
- }
- if ($firstitem) {echo 'Not a sausage!';}
- echo '<br/>Cash: ' . $_SESSION['cash'] . ' Score: ' . $_SESSION['score'];
- echo '</div>';
- }
- echo '<p>
- <a href="http://www.minild12.sophiehoulden.com/index.php?title=Adventure/'.$page.'&action=edit">Edit this page!</a><br/>
- Feel free to add pages to the game <a href="http://www.minild12.sophiehoulden.com/index.php?title=Adventure">here!</a>
- </p>';
- textSectionEnd();
- echo '<br />';
- include("footer.php");
- echo '</div>';
- if (!in_array($page, $_SESSION['visited']))
- {
- $_SESSION['visited'][] = $page;
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment