Skip to content

Instantly share code, notes, and snippets.

@chocolatkey
Last active May 6, 2016 17:50
Show Gist options
  • Save chocolatkey/2d244a72ffa7628cb306b0e809a471cb to your computer and use it in GitHub Desktop.
Save chocolatkey/2d244a72ffa7628cb306b0e809a471cb to your computer and use it in GitHub Desktop.
Foolslide latest releases fetcher for front page presentation (Foundation 5)
<?php
//FoolSlide RSS Feed loader/formatter v2
//Henry Stark 2016
//ini_set('display_errors', 1);
//error_reporting(E_ALL ^ E_NOTICE);
//CONFIG///////////////////////////////
$url_prefix = "//PATH_TO_FOOLSLIDE/";//Fooslide location
require_once("/PATH_TO_medoo.php");//Path to medoo
//Comic DB
$comic_database = new medoo([
// required
'database_type' => 'mysql',
'database_name' => "DATABASE",
'server' => "DOMAIN",
'username' => "USERNAME",
'password' => "PASSWORD",
'charset' => 'utf8',
// optional
'port' => 3306,
// driver_option for connection, read more from http://www.php.net/manual/en/pdo.setattribute.php
'option' => [
PDO::ATTR_CASE => PDO::CASE_NATURAL
]
]);
//END CONFIG//////////////////////////
$chapters = $comic_database->select("fs_chapters", [
"id",
"volume",
"chapter",
"subchapter",
"language",
"created",
"stub",
"uniqid",
"comic_id"
], [
"AND" => [
"hidden" => 0
],
"LIMIT" => 25,
"ORDER" => "created DESC",
]);
//Date stuff here, including this function from https://stackoverflow.com/questions/2915864/php-how-to-find-the-time-elapsed-since-a-date-time
function get_time_ago_string($time_stamp, $divisor, $time_unit)
{
$time_difference = strtotime("now") - $time_stamp;
$time_units = floor($time_difference / $divisor);
settype($time_units, 'string');
if ($time_units === '0')
{
return 'less than 1 ' . $time_unit . ' ago';
}
elseif ($time_units === '1')
{
return '1 ' . $time_unit . ' ago';
}
else
{
/*
* More than "1" $time_unit. This is the "plural" message.
*/
// TODO: This pluralizes the time unit, which is done by adding "s" at the end; this will not work for i18n!
return $time_units . ' ' . $time_unit . 's ago';
}
}
$i = 0;
foreach ($chapters as $chapter) {
$comic = $comic_database->select("fs_comics", [
"stub",
"uniqid",
"thumbnail",
"name"
], [
"AND" => [
"hidden" => 0,
"id" => $chapter["comic_id"]
]
]);
$img = $url_prefix."content/comics/".$comic[0]["stub"]."_".$comic[0]["uniqid"]."/thumb_".$comic[0]["thumbnail"];
$link = $url_prefix."read/".$comic[0]["stub"]."/".$chapter["language"]."/".$chapter["volume"]."/".$chapter["chapter"]."/";
$title = "<b>".$comic[0]["name"]."</b> ";
if ($chapter["chapter"] > 0) { // if chapter == 0 it means this is a one-shot
if (!empty($chapter["name"])) { // support for custom chapter titles
$title .= $chapter["name"];
}
else {
$title .= "Chapter" . ' ' . $chapter["chapter"];
}
}
if (!empty($chapter["subchapter"]) && $chapter["chapter"] > 0) { // if it's a one-shot, we still use subchapter for sorting, but don't display it
$title .= '.' . $chapter["subchapter"];
}
if (!empty($chapter["name"])) {
// if it's a one-shot with title, hide the : because there's no numbering
if ($chapter["chapter"] > 0) {
$title .= ': ';
}
$title .= $chapter["name"];
}
else {
if ($chapter["chapter"] == 0) {
// one-shots without a title gets the comic title
$title .= $comic["name"];
}
}
//$title = $comic[0]["name"]." Chapter ".$chapter["chapter"];
$created = strtotime($chapter["created"]);
$time_difference = strtotime('now') - $created;
if ($time_difference >= 60 * 60 * 24) {
/*
* 60 seconds/minute * 60 minutes/hour * 24 hours/day
* This means that the time difference is 1 day or more (show as normal date)
*/
$created = substr($chapter["created"], 0, 10);
} elseif ($time_difference >= 60 * 60) {
/*
* 60 seconds/minute * 60 minutes/hour
* This means that the time difference is 1 hour or more
*/
$created = get_time_ago_string($created, 60 * 60, 'hour');
} else {
/*
* 60 seconds/minute
* This means that the time difference is a matter of minutes
*/
$created = get_time_ago_string($created, 60, 'minute');
}
echo '<hr />' . PHP_EOL;
if($i > 2){
if($i == 3) {
echo '<div id="ffeed" class="ws" style="height: 350px;">' . PHP_EOL;
}
echo '<h4><a href="' . $link . '">' . $title . '</a></h4>' . PHP_EOL;
echo '<p>Released: ' . $created . '</p>' . PHP_EOL;
} else {
echo '<div class="row">' . PHP_EOL;
echo '<div class="large-3 medium-3 columns"><a class="th" href="' . $link . '"><img src="' . $img . '"></img></a></div>' . PHP_EOL;
echo '<div class="large-9 medium-9 columns"><h4><a href="' . $link . '">' . $title . '</a></h4>' . PHP_EOL;
echo '<p>Released: ' . $created . '</p></div>' . PHP_EOL;
echo '</div>' . PHP_EOL;
}
$i++;
}
echo '<hr /><p>Looking for something older? Check <a href="' . $url_prefix . 'latest/2/">here</a></p>';
if($i > 2) {
echo '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment