add schedule (mostly writen by Vencislav)
This commit is contained in:
parent
8da476a058
commit
6f94733908
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/* Template Name: Schedule */
|
||||
get_header();
|
||||
$content = require __DIR__ . DIRECTORY_SEPARATOR . 'schedule' . DIRECTORY_SEPARATOR . 'parse.php';
|
||||
//var_dump($data);
|
||||
?>
|
||||
<section class="content">
|
||||
<h1>Програма</h1>
|
||||
<table border="1" style="text-align: center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<?php
|
||||
foreach ($content['halls'] as $hall_name) {
|
||||
?>
|
||||
<td><?php echo htmlspecialchars($hall_name); ?></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($content['lines'] as $line) {
|
||||
echo $line, PHP_EOL;
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="separator"></div>
|
||||
<?php
|
||||
foreach ($content['fulltalks'] as $line) {
|
||||
echo $line, PHP_EOL;
|
||||
}
|
||||
|
||||
foreach ($content['gspk'] as $line) {
|
||||
echo $line, PHP_EOL;
|
||||
}
|
||||
|
||||
foreach ($content['fspk'] as $line) {
|
||||
echo $line, PHP_EOL;
|
||||
}
|
||||
?>
|
||||
<div class="separator"></div>
|
||||
<div class="col-right sponsors sponsors-frontpage">
|
||||
<?php echo do_shortcode( '[sponsors]' ); ?>
|
||||
<?php echo do_shortcode( '[partners]' ); ?>
|
||||
</div>
|
||||
<div class="separator"></div>
|
||||
</section>
|
||||
|
||||
<?php echo do_shortcode( '[transport]' ); ?>
|
||||
|
||||
<?php get_footer(); ?>
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
class SmartCurl {
|
||||
protected static $etags = [];
|
||||
protected $ch = null;
|
||||
protected $cache_dir = __DIR__ . DIRECTORY_SEPARATOR . 'cache';
|
||||
protected $cache_index;
|
||||
protected $url_root = null;
|
||||
|
||||
public function __construct($url_root = null, $cache_dir = null) {
|
||||
if (!is_null($cache_dir)) {
|
||||
$this->cache_dir = __DIR__ . DIRECTORY_SEPARATOR . $cache_dir;
|
||||
}
|
||||
|
||||
if (!file_exists($this->cache_dir)) {
|
||||
mkdir($this->cache_dir);
|
||||
}
|
||||
|
||||
$this->cache_index = $this->cache_dir . '.json';
|
||||
|
||||
$cache = file_exists($this->cache_index) ? file_get_contents($this->cache_index) : false;
|
||||
|
||||
if ($cache !== false) {
|
||||
$cache = json_decode($cache, true);
|
||||
}
|
||||
|
||||
if ($cache !== false) {
|
||||
static::importEtags($cache);
|
||||
}
|
||||
|
||||
if (!is_null($url_root)) {
|
||||
$this->url_root = $url_root;
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
if ($ch === false) {
|
||||
throw new Exception('curl init failed');
|
||||
}
|
||||
|
||||
$this->ch = $ch;
|
||||
|
||||
if (curl_setopt_array($ch, [
|
||||
CURLOPT_FAILONERROR => true,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
//CURLINFO_HEADER_OUT => true,
|
||||
]) === false) {
|
||||
throw new Exception('curl setopt failed');
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
curl_close($this->ch);
|
||||
file_put_contents($this->cache_index, json_encode(static::exportEtags()));
|
||||
}
|
||||
|
||||
public static function importEtags(array $etags) {
|
||||
static::$etags = array_merge(static::$etags, $etags);
|
||||
}
|
||||
|
||||
public static function exportEtags() {
|
||||
return static::$etags;
|
||||
}
|
||||
|
||||
public function getUrl($filename) {
|
||||
if (is_null($this->url_root)) {
|
||||
$url = $filename;
|
||||
}
|
||||
else {
|
||||
$url = $this->url_root . $filename;
|
||||
}
|
||||
|
||||
if (curl_setopt($this->ch, CURLOPT_URL, $url) === false) {
|
||||
throw new Exception('set url failed');
|
||||
}
|
||||
|
||||
$cache_file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename;
|
||||
|
||||
$etag = array_key_exists($url, static::$etags) && file_exists($cache_file) ? static::$etags[$url] : null;
|
||||
|
||||
if (curl_setopt($this->ch, CURLOPT_HTTPHEADER, [
|
||||
'If-None-Match:' . (is_null($etag) ? '' : ' ' . $etag),
|
||||
]) === false) {
|
||||
throw new Exception('set etag failed');
|
||||
}
|
||||
|
||||
$response = curl_exec($this->ch);
|
||||
|
||||
if ($response === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
|
||||
//var_dump($response);
|
||||
|
||||
$header_size = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
|
||||
$header = substr($response, 0, $header_size);
|
||||
$headers = array_filter(explode("\r\n", $header));
|
||||
|
||||
foreach ($headers as $header_line) {
|
||||
if (stripos($header_line, 'etag:') === 0) {
|
||||
static::$etags[$url] = trim(substr($header_line, strlen('etag:')));
|
||||
}
|
||||
}
|
||||
|
||||
$http_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($http_code === 304 && !is_null($this->url_root)) {
|
||||
// use cache
|
||||
|
||||
if (file_exists($cache_file)) {
|
||||
return file_get_contents($cache_file);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($response) === $header_size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$body = substr($response, $header_size);
|
||||
|
||||
if ($http_code === 200) {
|
||||
$dirname = dirname($filename);
|
||||
|
||||
if ($dirname !== '.') {
|
||||
mkdir($this->cache_dir . DIRECTORY_SEPARATOR . $dirname, 0777, true);
|
||||
}
|
||||
|
||||
file_put_contents($cache_file, $body);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Test schedule</title>
|
||||
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="http://www.openfest.org/2014/wp-content/themes/initfest/style.css" />
|
||||
</head>
|
||||
<pre>
|
||||
<?php
|
||||
//header('Content-Type: text/plain; charset=utf-8');
|
||||
error_reporting(~0);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$content = require __DIR__ . DIRECTORY_SEPARATOR . 'parse.php';
|
||||
?>
|
||||
</pre>
|
||||
<table border="1" style="text-align: center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<?php
|
||||
foreach ($content['halls'] as $hall_name) {
|
||||
?>
|
||||
<td><?php echo htmlspecialchars($hall_name); ?></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($content['lines'] as $line) {
|
||||
echo $line, PHP_EOL;
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="separator"></div>
|
||||
<?php
|
||||
foreach ($content['fulltalks'] as $line) {
|
||||
echo $line, PHP_EOL;
|
||||
}
|
||||
|
||||
foreach ($content['gspk'] as $line) {
|
||||
echo $line, PHP_EOL;
|
||||
}
|
||||
|
||||
foreach ($content['fspk'] as $line) {
|
||||
echo $line, PHP_EOL;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
require __DIR__ . DIRECTORY_SEPARATOR . 'class.SmartCurl.php';
|
||||
|
||||
$base_url = 'https://cfp.openfest.org/api/conferences/2/';
|
||||
|
||||
$filenames = [
|
||||
'events' => 'events.json',
|
||||
'speakers' => 'speakers.json',
|
||||
'tracks' => 'tracks.json',
|
||||
'event_types' => 'event_types.json',
|
||||
'halls' => 'halls.json',
|
||||
'slots' => 'slots.json',
|
||||
];
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($filenames as $name => $filename) {
|
||||
$curl = new SmartCurl($base_url);
|
||||
$json = $curl->getUrl($filename);
|
||||
|
||||
if ($json === false) {
|
||||
echo 'get failed: ', $filename, PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, true);
|
||||
|
||||
if ($decoded === false) {
|
||||
echo 'decode failed: ', $filename, PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
$add = true;
|
||||
|
||||
switch ($name) {
|
||||
case 'halls':
|
||||
$decoded = array_map(function($el) {
|
||||
return $el['name'];
|
||||
}, $decoded);
|
||||
break;
|
||||
case 'slots':
|
||||
$decoded = array_map(function($el) {
|
||||
foreach (['starts_at', 'ends_at'] as $key) {
|
||||
$el[$key] = strtotime($el[$key]);
|
||||
}
|
||||
|
||||
return $el;
|
||||
}, $decoded);
|
||||
break;
|
||||
}
|
||||
|
||||
$data[$name] = $decoded;
|
||||
}
|
||||
|
||||
function compareKeys($a, $b, $key) {
|
||||
$valA = &$a[$key];
|
||||
$valB = &$b[$key];
|
||||
|
||||
return ($valA < $valB) ? -1 : (($valA > $valB) ? 1 : 0);
|
||||
}
|
||||
|
||||
uasort($data['slots'], function($a, $b) {
|
||||
return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id');
|
||||
});
|
||||
|
||||
array_pop($data['halls']);
|
||||
|
||||
return $data;
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
// 'halfnarp_friendly'
|
||||
// 'events'
|
||||
// 'speakers'
|
||||
// 'tracks' [en/bg]
|
||||
// 'event_types' [en/bg]
|
||||
// 'halls'
|
||||
// 'slots'
|
||||
|
||||
$data = require __DIR__ . DIRECTORY_SEPARATOR . 'load.php';
|
||||
|
||||
$cut_len = 50;
|
||||
$cfp_url = 'http://cfp.openfest.org';
|
||||
$time = 0;
|
||||
$date = 0;
|
||||
$lines = [];
|
||||
$fulltalks = [];
|
||||
$prev_event_id = 0;
|
||||
$colspan = 1;
|
||||
$hall_ids = array_keys($data['halls']);
|
||||
$first_hall_id = min($hall_ids);
|
||||
$last_hall_id = max($hall_ids);
|
||||
|
||||
foreach ($data['slots'] as $slot_id => $slot) {
|
||||
$slotTime = $slot['starts_at'];
|
||||
$slotDate = date('d', $slotTime);
|
||||
|
||||
if ($slotDate !== $date) {
|
||||
$lines[] = '<tr>';
|
||||
$lines[] = '<td>' . date('d F - l', $slotTime) . '</td>';
|
||||
$lines[] = '<td colspan="3"> </td>';
|
||||
$lines[] = '</tr>';
|
||||
|
||||
$date = $slotDate;
|
||||
}
|
||||
|
||||
if ($slotTime !== $time) {
|
||||
if ($time !== 0) {
|
||||
$lines[] = '</tr>';
|
||||
}
|
||||
|
||||
$lines[] = '<tr>';
|
||||
$lines[] = '<td>' . date('H:i', $slot['starts_at']) . ' - ' . date('H:i', $slot['ends_at']) . '</td>';
|
||||
|
||||
$time = $slotTime;
|
||||
}
|
||||
|
||||
$eid = &$slot['event_id'];
|
||||
$event = &$data['events'][$eid];
|
||||
|
||||
if (is_null($eid)) {
|
||||
$lines[] = '<td>TBA</td>';
|
||||
}
|
||||
else {
|
||||
$title = mb_substr($event['title'], 0, $cut_len) . (strlen($event['title']) > $cut_len ? '...' : '');
|
||||
$speakers = '';
|
||||
|
||||
if (count($event['participant_user_ids']) > 0) {
|
||||
$speakers = json_encode($event['participant_user_ids']) . '<br>';
|
||||
|
||||
$spk = array();
|
||||
$speaker_name = array();
|
||||
foreach ($event['participant_user_ids'] as $uid) {
|
||||
/* The check for uid==4 is for us not to show the "Opefest Team" as a presenter for lunches, etc. */
|
||||
if ($uid == 4 || empty ($data['speakers'][$uid])) {
|
||||
continue;
|
||||
} else {
|
||||
/* TODO: fix the URL */
|
||||
$name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name'];
|
||||
$spk[$uid] = '<a class="vt-p" href="#'. $name . '">' . $name . '</a>';
|
||||
}
|
||||
}
|
||||
$speakers = implode (', ', $spk);
|
||||
}
|
||||
|
||||
|
||||
/* Hack, we don't want language for the misc track. This is the same for all years. */
|
||||
if ('misc' !== $data['tracks'][$event['track_id']]['name']['en']) {
|
||||
$csslang = "schedule-".$event['language'];
|
||||
} else {
|
||||
$csslang = "";
|
||||
}
|
||||
$cssclass = &$data['tracks'][$event['track_id']]['css_class'];
|
||||
$style = ' class="' . $cssclass . ' ' . $csslang . '"';
|
||||
$content = '<a href=#lecture-' . $eid . '>' . htmlspecialchars($title) . '</a> <br>' . $speakers;
|
||||
|
||||
|
||||
/* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */
|
||||
$fulltalks[$eid] = '';
|
||||
$fulltalks[$eid] .= '<section id="lecture-' . $eid . '">';
|
||||
/* We don't want '()' when we don't have a speaker name */
|
||||
$fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : '';
|
||||
$fulltalks[$eid] .= '<p><strong>' . $event['title'] . ' ' . $fulltalk_spkr . '</strong>';
|
||||
$fulltalks[$eid] .= '<p>' . $event['abstract'] . '</p>';
|
||||
$fulltalks[$eid] .= '<div class="separator"></div>';
|
||||
|
||||
if ($slot['event_id'] === $prev_event_id) {
|
||||
array_pop($lines);
|
||||
$lines[] = '<td' . $style . ' colspan="' . ++$colspan . '">' . $content . '</td>';
|
||||
}
|
||||
else {
|
||||
$lines[] = '<td' . $style . '>' . $content . '</td>';
|
||||
$colspan = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$prev_event_id = $slot['event_id'];
|
||||
}
|
||||
|
||||
$lines[] = '</tr>';
|
||||
|
||||
$gspk = [];
|
||||
$fspk = [];
|
||||
$types = [];
|
||||
$types['twitter']['url']='https://twitter.com/';
|
||||
$types['twitter']['class']='fa fa-twitter';
|
||||
$types['github']['url']='https://github.com/';
|
||||
$types['github']['class']='fa fa-github';
|
||||
$types['email']['url']='mailto:';
|
||||
$types['email']['class']='fa fa-envelope';
|
||||
|
||||
$gspk[] = '<div class="grid members">';
|
||||
|
||||
foreach ($data['speakers'] as $speaker) {
|
||||
$name = $speaker['first_name'] . ' ' . $speaker['last_name'];
|
||||
|
||||
$gspk[] = '<div class="member col4">';
|
||||
$gspk[] = '<a href="#' . $name . '">';
|
||||
$gspk[] = '<img width="100" height="100" src="' . $cfp_url . $speaker['picture']['schedule']['url'].'" class="attachment-100x100 wp-post-image" alt="' . $name .'" />';
|
||||
$gspk[] = '</a> </div>';
|
||||
|
||||
$fspk[] = '<div class="speaker" id="' . $name . '">';
|
||||
$fspk[] = '<img width="100" height="100" src="' . $cfp_url . $speaker['picture']['schedule']['url'].'" class="attachment-100x100 wp-post-image" alt="' . $name .'" />';
|
||||
$fspk[] = '<h3>' . $name . '</h3>';
|
||||
$fspk[] = '<div class="icons">';
|
||||
foreach ($types as $type => $parm) {
|
||||
if (!empty($speaker[$type])) {
|
||||
$fspk[] = '<a href="'. $parm['url'] . $speaker[$type] . '"><i class="' . $parm['class'] . '"></i></a>';
|
||||
}
|
||||
}
|
||||
$fspk[] = '<p>' . $speaker['biography'] . '</p>';
|
||||
$fspk[] = '</div><div class="separator"></div>';
|
||||
}
|
||||
|
||||
$gspk[] = '</div>';
|
||||
|
||||
return array_merge($data, compact('lines', 'fulltalks', 'gspk', 'fspk'));
|
Loading…
Reference in New Issue