Created
April 28, 2018 00:17
-
-
Save phpdreams/e0c7594d8d355e8fb294d2fe63c1d766 to your computer and use it in GitHub Desktop.
Speaker List Cache Generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
That's so helpful for a code newbie, like me. Thanks so much for sharing!
Thanks for sharing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great clever method, thanks.
from Quora https://www.quora.com/Why-do-some-people-still-use-pure-PHP-if-there-are-so-many-incredible-PHP-frameworks-like-Laravel/answer/Bill-Wheeler-4?share=13ecec34&srid=nrkL