Episode Generator Code

==Adding New Campaigns==
 <section id='Tombs_of_Scoria'> //ID Optional
 Tombs of Scoria // Campaign name
        /*Function call, sends 
        -Navbox link
        -Youtube:
          0 - Singular youtube link
          1 - Multiple links
        -Reddit:
          0 - No reddit links
          1 - 1 reddit link
          >1 - 2 reddit links
        -Animation:
          0 - No animation link
          1 - Animation link
        -Ingame date
          0 - No date in recap
          1 - Date in recap */
 <?php printData('https://regalgoblins.fandom.com/wiki/Template:Navbox_ToS', 0, 2, 1, 1); ?>
 </section>
==Source Code==
<html lang="en">
<?php
date_default_timezone_set('America/Los_Angeles');
function stripLink($link)
{
 $link = str_replace("/wiki/", , $link);
 $link = str_replace("https://regalgoblins.fandom.com", , $link);
 $link = str_replace("Template:", , $link);
 $link = str_replace("_", ' ', $link);
 $link = html_entity_decode($link);
 return $link;
}
function generateLink($link)
{
 $href = stripLink($link->getAttribute('href'));
 $text = $link->textContent;
 return ($href === $text) ? '[[' . $text . ']]' : '[[' . $href . '|' . $text . ']]';
}
function getLatestEpisode($link)
{
 $html = file_get_contents($link);
 $dom = new DOMDocument();
 @$dom->loadHTML($html); // @ - Don't do this, don't ever EVER do this
 $finder = new DomXPath($dom);
 $dom = $finder->query("//*[contains(@class, 'navbox-list')]");
 $dom = $dom->item($dom->length - 1);
 $dom = $dom->getElementsByTagName('a');
 $dom = $dom->item($dom->length - 1);
 return $dom;
}
function getSmallImage($campaign){
 $html = file_get_contents('https://regalgoblins.fandom.com'.$campaign); 
 
 $dom = new DOMDocument();
 @$dom->loadHTML($html);
 $finder = new DomXPath($dom);
 $dom = $finder->query("//*[contains(@class, 'noCaption')]");
 $dom = $dom->item($dom->length - 1)->getElementsByTagName('img');
 $dom = $dom->item(0)->getAttribute('data-image-name');
 return $dom;
}
function fetchData($link, $maxCharsBig, $maxCharsSmall, $dateBool)
{
 $lastEp = getLatestEpisode($link);
 $epLink = $lastEp->getAttribute('href');
 $epID = filter_var($epLink, FILTER_SANITIZE_NUMBER_INT);
 $next = str_replace($epID, sprintf("%02d", intval($epID) + 2), stripLink($epLink));
 $currentLink = str_replace($epID, sprintf("%02d", intval($epID) + 1), stripLink($epLink));
 $category = stripLink($epLink);
 $category = preg_replace('/[0-9]+/', , $category);
 $category = rtrim($category, " ") . 's';
 $pos = strrpos($category, ':');
 if ($pos) $category = substr_replace($category, , $pos, 1);
 $dataArray = array(
 'image' => ,
 'smallImage'=> ,
 'caption' => ,
 'campaign' => ,
 'episode' => 'Episode ' . sprintf("%02d", intval($epID) + 1),
 'createdBy' => '[[Neal Pass Erickson]]',
 'airDate' => date('jS F Y'),
 'youtube' => ,
 'twitch' => htmlentities('<!--[[File:Twitch20px.png|Twitch Vod||link=]]-->'),
 'reddit' => ,
 'animation' => ,
 'prev' => generateLink($lastEp),
 'epLink' => '[[' . $currentLink . '|Episode ' . sprintf("%02d", intval($epID) + 1) . ']]',
 'next' => '{{#ifexist:' . $next . '|[[' . $next . '|Episode ' . sprintf("%02d", intval($epID) + 2) . ']]|}}',
 'castBig' => ,
 'castSmall' => ,
 'gameDate' => ,
 'category' => $category
 );
 $html = file_get_contents('https://regalgoblins.fandom.com'.$epLink);
 $dom = new DOMDocument();
 @$dom->loadHTML($html);
 $finder = new DomXPath($dom);
 // *** INGAME DATE ***
 if ($dateBool) {
 $date = $finder->query("//*[contains(@class, 'mw-parser-output')]");
 $date = $date->item(0);
 $date = $date->getElementsByTagName('h3');
 $date = $date->item($date->length - 1);
 $date = $date->getElementsByTagName('span');
 if (!$date->item(0)->textContent) $date = $date->item(1);
 else $date = $date->item(0);
 $dataArray['gameDate'] = $date->textContent;
 }
 // *** CAMPAIGN NAME ***
 $campaign = $finder->query("//*[contains(@class, 'pi-data')]");
 $campaign = $campaign->item(0)->getElementsByTagName('a')->item(0);
 $dataArray['campaign']=generateLink($campaign);
 
 
 $dataArray['smallImage']=getSmallImage($campaign->getAttribute('href'));
 
 // *** IMAGE DATA ***
 $img = $finder->query("//*[contains(@class, 'pi-image')]");
 $img = $img->item(0);
 $dataArray['image'] = $img->getElementsByTagName('img')->item(0)->getAttribute('data-image-name');
 if ($img->getElementsByTagName('figcaption')->item(0)) {
 $img = $img->getElementsByTagName('figcaption')->item(0);
 if (substr( $img->getElementsByTagName('a')->item(0)->getAttribute('href'), 0, 5 ) === "/wiki") {
 $dataArray['caption'] = generateLink($img->getElementsByTagName('a')->item(0));
 }
 else {
 $dataArray['caption'] = str_replace($img->getElementsByTagName('a')->item(0)->textContent, '[' .
 stripLink($img->getElementsByTagName('a')->item(0)->getAttribute('href')) . ' ' . $img->getElementsByTagName('a')->item(0)->textContent . ']', $img->textContent);
 }
 }
 
 // *** CAST ***
 $i=0;
 $dom = $finder->query("//*[contains(@class, 'pi-group')]");
 $dom = $dom->item($dom->length - 1);
 $dom = $dom->getElementsByTagName('div');
 foreach ($dom as $player) {
 if ($player->getAttribute('data-source')) {
 if ($player->getElementsByTagName('a')->item(0)) $name = generateLink($player->getElementsByTagName('a')->item(0)); else $name='?';
 $charName = ;
 if ($player->getElementsByTagName('a')->item(1)) $charName = generateLink($player->getElementsByTagName('a')->item(1));
 else {
 if ($player->getElementsByTagName('a')->item(0)) {
 $player->getElementsByTagName('div')->item(0)->removeChild($player->getElementsByTagName('a')->item(0));
 $charName = trim(str_replace(' - ', , $player->textContent), " \t\n\r"); }
 }
 $dataArray['castBig'] .= '|' . $player->getAttribute('data-source') . str_repeat(' ', $maxCharsBig - 1 - strlen($player->getAttribute('data-source'))) . ' = ' .
 $name . ' - ' . $charName . '{{br}}';
 
 if($campaign->textContent==='Dicing with Death')
 $dataArray['castSmall'] .= '|' . $player->getAttribute('data-source') . str_repeat(' ', $maxCharsSmall - 1 - strlen($player->getAttribute('data-source'))) . ' = ' .
 $name . ' - ' . $charName . '{{br}}'; else {
 $dataArray['castSmall'] .= '|' . $player->getAttribute('data-source') . str_repeat(' ', $maxCharsSmall - 1 - strlen($player->getAttribute('data-source'))) . ' = ' .
 $name. '{{br}}' ;}
 if(!$i) { 
 if($campaign->textContent === 'Shenanigans')$dataArray['castSmall'] = '|' . $player->getAttribute('data-source') . str_repeat(' ', $maxCharsSmall - 1 - strlen($player->getAttribute('data-source'))) . ' = ' .
 $name. ' - DM{{br}}' ;
 if($campaign->textContent === 'Pawns and Patrons') $dataArray['castSmall'] = '|DM'. str_repeat(' ', $maxCharsSmall - 1 - strlen($player->getAttribute('data-source'))) . ' = [[Steven Lumpkin]]{{br}}';
 $i++;
 }
 }
 }
 return $dataArray;
}
function printData($navBoxLink, $youtube = 0, $reddit = 0, $animation = 0, $dateBool = 0)
{
 $maxChars = 14;
 $maxCharsSmall = 9;
 $dataArray = fetchData($navBoxLink, $maxChars, $maxCharsSmall, $dateBool);
 // *** YOUTUBE ***
 if ($youtube)
 $dataArray['youtube'] = htmlentities("<!--[[File:Youtube20px.png|Youtube Vid||link=]] · [[File:Youtube20px.png|Youtube Vid||link=]] · -->");
 else $dataArray['youtube'] = htmlentities("<!--[[File:Youtube20px.png|Youtube Vid||link=]]-->");
 // *** REDDIT ***
 if ($reddit > 1)
 $dataArray['reddit'] = htmlentities("<!--[[File:Reddit20px.png|Reddit Discussion|link=]] · [[File:Reddit20px.png|Reddit Discussion|link=]]-->");
 else if ($reddit) $dataArray['reddit'] = htmlentities("<!--[[File:Reddit20px.png|Reddit Discussion|link=]]-->");
 // *** Animation ***
 if ($animation) $dataArray['animation'] = htmlentities("<!--[[File:Youtube20px.png|Animation||link=]]-->");
 echo '' .
 '<button onClick="copy(this)"/>Copy</button>' .
 '' .
 '{{stub}}__NOTOC__</br>' .
 '{{Infobox Episode</br>' .
 '|Image' . str_repeat(' ', $maxChars - strlen('Image')) . '= ' . $dataArray['image'] . "</br>" .
 '|Caption' . str_repeat(' ', $maxChars - strlen('Caption')) . '= ' . $dataArray['caption'] . '</br>' .
 '|Series' . str_repeat(' ', $maxChars - strlen('Series')) . '= ' . $dataArray['campaign'] . '</br>' .
 '|Episode' . str_repeat(' ', $maxChars - strlen('Episode')) . '= ' . $dataArray['episode'] . '</br>' .
 '|Created by' . str_repeat(' ', $maxChars - strlen('Created by')) . '= ' . $dataArray['createdBy'] . '</br>' .
 '|First Aired' . str_repeat(' ', $maxChars - strlen('First Aired')) . '= ' . $dataArray['airDate'] . '</br>' .
 '|Youtube Vid' . str_repeat(' ', $maxChars - strlen('Youtube Vid')) . '= ' . $dataArray['youtube'] . '</br>' .
 '|Twitch Vid' . str_repeat(' ', $maxChars - strlen('Twitch Vid')) . '= ' . $dataArray['twitch'] . '</br>' ;
 if($reddit) echo '|Reddit Thread' . str_repeat(' ', $maxChars - strlen('Reddit Thread')) . '= ' . $dataArray['reddit'] . '</br>' ;
 if($animation) echo '|Animation' . str_repeat(' ', $maxChars - strlen('Animation')) . '= ' . $dataArray['animation'] . '</br>' ;
 echo
 '|Prev Episode' . str_repeat(' ', $maxChars - strlen('Prev Episode')) . '= ' . $dataArray['prev'] . '</br>' .
 '|Next Episode' . str_repeat(' ', $maxChars - strlen('Next Episode')) . '= ' . $dataArray['next'] . '</br>' .
 $dataArray['castBig'] .
 '}}</br>';
 echo '==Recap==</br>';
 if ($dateBool) echo '===' . $dataArray['gameDate'] . '===</br>';
 echo htmlentities(" Recap to be added. ") . '</br></br>' .
 '==Experience==</br>' .
 '{{' . stripLink($navBoxLink) . '}}</br>' .
 '[[Category:' . stripLink($dataArray['category']) . ']]' .
 '' .
 '';
 $dataArray['youtube'] = htmlentities("<!--[[File:Youtube20px.png|Youtube Vid||link=]]-->");
 echo '' .
 '<button onClick="copy(this)"/>Copy</button>' .
 '' .
 '{{EpisodeList</br>' .
 '|image' . str_repeat( html_entity_decode(' '), $maxCharsSmall - strlen('image')) . '= ' . $dataArray['smallImage'] . '</br>' .
 '|title' . str_repeat(' ', $maxCharsSmall - strlen('title')) . '= ' . $dataArray['epLink'] . '</br>' .
 '|airdate' . str_repeat(' ', $maxCharsSmall - strlen('airdate')) . '= ' . $dataArray['airDate'] . '</br>' .
 '|twitch' . str_repeat(' ', $maxCharsSmall - strlen('twitch')) . '= ' . $dataArray['twitch'] . '</br>' .
 '|youtube' . str_repeat(' ', $maxCharsSmall - strlen('youtube')) . '= ' . $dataArray['youtube'] . '</br>' ;
 if ($reddit) echo '|reddit' . str_repeat(' ', $maxCharsSmall - strlen('reddit')) . '= ' . $dataArray['reddit'] . '</br>' ;
 echo $dataArray['castSmall'] .
 '|summary' . str_repeat(' ', $maxCharsSmall - strlen('summary')) . '= ' . htmlentities(" ...") . '</br>' .
 '}}</br>' .
 '' .
 '';
}
?>
<head>
 <meta charset="utf-8">
 <title>Wiki Episode Generator</title>
 <link rel="preconnect" href="https://fonts.gstatic.com">
 <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@700&display=swap" rel="stylesheet">
</head>
<style>body,html{font-size:.9vw;background-color:#eaedf0;width:100%;margin:0;padding:0}.wrapper{max-width:1300px;width:80rem;display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-webkit-box-pack:justify;-ms-flex-pack:justify;justify-content:space-between;left:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%);position:relative}section{width:45%;padding:0;margin:0;margin-bottom:1rem;margin-top:2rem}div{position:relative}div>button{-webkit-box-shadow:0 .2rem .8rem .2rem rgba(187,30,52,.5);box-shadow:0 .2rem .8rem .2rem rgba(187,30,52,.5);font-family:Quicksand,Lato,sans-serif;font-size:1rem;position:absolute;bottom:1.8rem;right:2.1rem;display:inline-block;border:none;border-radius:50px;padding:.8rem 1.3rem;background-color:#bb1e34;color:#fff;outline:0;cursor:pointer}div>button:active{-webkit-transform:scale(.95);transform:scale(.95);background-color:#a81b2f}code{white-space: pre;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-box-shadow:inset 0 0 1.5rem .3rem rgba(56,89,123,.1);box-shadow:inset 0 0 1.5rem .3rem rgba(56,89,123,.1);font-size:20px;font-size:.65rem;display:block;background-color:#e2e8ef;border-radius:10px;margin-top:1.3rem;padding:1.8rem;overflow-x:hidden;color:#2c3541;min-height:43vh;font-family:monospace}span{color:#bb1e34}code:hover{-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text}.sc{min-height:23vh}h2{white-space:nowrap;font-family:Quicksand,Lato,sans-serif;font-size:2.3rem;color:#2c3541;position:relative;padding-left:1.8rem;margin:0;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}h2::after{content:;position:absolute;height:110%;width:.3rem;background-color:#bb1e34;border-radius:10px;left:0;top:-3%}header{-webkit-box-shadow:0 0 .5rem 0 rgba(56,89,123,.16);box-shadow:0 0 .5rem 0 rgba(56,89,123,.16);height:3.5rem}footer{width:100%;height:5rem}nav{left:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%);position:relative;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-ms-flex-pack:justify;justify-content:space-between;height:100%;max-width:1300px;width:80rem;font-family:Quicksand,Lato,sans-serif;-webkit-box-align:center;-ms-flex-align:center;align-items:center;font-size:.9rem}nav div{width:35%;display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-pack:justify;-ms-flex-pack:justify;justify-content:space-between}a{color:#2c3541;text-decoration:none;font-family:inherit}@media screen and (min-width:1925px){html{font-size:18px}}</style>
<body>
 <header>
 <nav>
 <a href='#Deadly_Dungeon'>Deadly Dungeon</a>
 <a href='#Dicing_with_Death'>DwD: Divan</a>
 <a href='#EmbersOfTheWilds'>Embers Of The Wilds</a>
 <a href='#LAG'>Legends of Arcadia:Genesis</a>
 <a href='#Pawns_and_Patrons'>Pawns and Patrons</a>
 <a href='#Tombs_of_Scoria'>Tombs of Scoria</a>
 </nav>
 </header>
 
 <section id='Tombs_of_Scoria'>
 <a href= target="_blank">Tombs of Scoria</a>
 <?php printData('https://regalgoblins.fandom.com/wiki/Template:Navbox_ToS', 0, 2, 1, 1); ?>
 </section>
 
 <section id="EmbersOfTheWilds">
 Embers Of The Wilds
 <?php printData('https://regalgoblins.fandom.com/wiki/Template:Navbox_EotW', 0, 1, 0, 0); ?>
 </section>
 <section id='Deadly_Dungeon'>
 Deadly Dungeon
 <?php printData('https://regalgoblins.fandom.com/wiki/Template:Navbox_FatalOne', 1, 0, 0, 0); ?>
 </section>
 <section id="LAG">
 Legends of Arcadia: Genesis
 <?php printData('https://regalgoblins.fandom.com/wiki/Template:Navbox_LAG', 1, 1, 0, 1); ?>
 </section>
 <section id="Dicing_with_Death">
 DwD: Divan
 <?php printData('https://regalgoblins.fandom.com/wiki/Template:Navbox_DwD_Divan', 1, 0, 0, 1); ?>
 </section>
 <section id="Pawns_and_Patrons">
 Pawns and Patrons
 <?php printData('https://regalgoblins.fandom.com/wiki/Template:Navbox_PnP', 1, 0, 0, 0); ?>
 </section>
 
 <footer>
 <nav>
 Last update: <?php echo date('jS F Y', '1616249032') ?> - EoW Added, , Shenanigans deleted, div wrapper deleted.
 
 <a href='https://regalgoblins.fandom.com/wiki/Arcadia_Wiki'>Arcadia Wiki</a>
 <a href='https://calendar.google.com/calendar/u/0/embed?src=r66id1eklub8t8d8f3q79tp3ak@group.calendar.google.com&ctz=UTC&pli=1'>Schedule</a>
 <a href='https://regalgoblins.com'>Regal Goblins</a>
 
 </nav>
 </footer>
 <script>
 function copy(obj) {
 var dummy = document.createElement("textarea");
 dummy.value = obj.nextSibling.innerText;
 document.body.appendChild(dummy);
 dummy.select();
 document.execCommand("copy");
 document.body.removeChild(dummy);
 }
 </script>
</body>
</html>
Category:Code for the Wiki