Skip to content

Instantly share code, notes, and snippets.

@phpdreams
Created April 28, 2018 00:17
Show Gist options
  • Save phpdreams/e0c7594d8d355e8fb294d2fe63c1d766 to your computer and use it in GitHub Desktop.
Save phpdreams/e0c7594d8d355e8fb294d2fe63c1d766 to your computer and use it in GitHub Desktop.
Speaker List Cache Generation
<?php
// this will read in all the speakers, sort them by date, then store in a file for use later
$speakerList = [
'speaker-file',
];
$speakers_all = [];
foreach($speakerList as $speaker) {
$speakers_all[$speaker] = include_once("./speakers/{$speaker}.php");
$speakers_all[$speaker]['bullet-points'] = text2bullets($speakers_all[$speaker]['bullet-points']);
}
// sort speakers by date/time
foreach($speakers_all as $slug => $speaker) {
$timeslot[$slug] = $speaker['datetime'];
}
array_multisort($timeslot, SORT_ASC, $speakers_all);
file_put_contents(__DIR__.'/_speaker_list.txt', json_encode($speakers_all));
echo "<h1>".count($speakers_all)." Speakers Cached</h1>";
function text2bullets($text) {
$lines = preg_split("/\r\n|\n|\r/", $text);
foreach($lines as $key => $line){
$lines[$key] = '<li>'.$line.'</li>';
}
return implode(PHP_EOL, $lines);
}
<?php
// this is data needed for each speaker
return [
'title' => 'xxx',
'datetime' => '2017-12-09 07:00:00',
'track' => 'track_1',
'video' => '',
'bullet-points' => <<<EOQ
EOQ
,
'description' => '',
'bonus_offer' => '',
'bonus_url' => '',
'bonus_desc' => '',
'name' => 'xxx',
'site_name' => '',
'site_url' => '',
'bio' => <<<EOQ
EOQ
];
<?php
// this is a portion of the file included on every page
$speakerList = file_get_contents(__DIR__.'/_speaker_list.txt');
if (empty($speakerList)) {
die("<h1>Must Build Speaker Cache");
}
$speakers_all = json_decode($speakerList, true);
@woodnti
Copy link

woodnti commented May 3, 2018

That's so helpful for a code newbie, like me. Thanks so much for sharing!

@abdelazizMahfouz
Copy link

Thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment