Rewrite the schedule generation script #31
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
function getSchedConfig($year = 2015) {
|
||||||
|
$globalConfig = [
|
||||||
|
'lang' => 'bg',
|
||||||
|
'cfp_url' => 'https://cfp.openfest.org',
|
||||||
|
'cut_len' => 70,
|
||||||
|
];
|
||||||
|
|
||||||
|
$config = [
|
||||||
|
2015 => [
|
||||||
|
'allowedHallIds' => [6, 7, 8],
|
||||||
|
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return array_merge($globalConfig, $config[$year]);
|
||||||
|
}
|
|
@ -2,7 +2,14 @@
|
||||||
error_reporting(~0);
|
error_reporting(~0);
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
define('SCHED_LANG', 'bg');
|
$requirePath = __DIR__ . DIRECTORY_SEPARATOR;
|
||||||
|
require $requirePath . 'class.SmartCurl.php';
|
||||||
|
require $requirePath . 'config.php';
|
||||||
|
require $requirePath . 'load.php';
|
||||||
|
require $requirePath . 'parse.php';
|
||||||
|
$sched_config = getSchedConfig();
|
||||||
|
$data = loadData($sched_config);
|
||||||
|
$content = parseData($sched_config, $data);
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -11,19 +18,14 @@ define('SCHED_LANG', 'bg');
|
||||||
<link rel="stylesheet" type="text/css" href="http://www.openfest.org/2014/wp-content/themes/initfest/style.css" />
|
<link rel="stylesheet" type="text/css" href="http://www.openfest.org/2014/wp-content/themes/initfest/style.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<pre>
|
|
||||||
<?php
|
|
||||||
$content = require __DIR__ . DIRECTORY_SEPARATOR . 'parse.php';
|
|
||||||
?>
|
|
||||||
</pre>
|
|
||||||
<table border="1" style="text-align: center;">
|
<table border="1" style="text-align: center;">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td> </td>
|
<td> </td>
|
||||||
<?php
|
<?php
|
||||||
foreach ($content['halls'] as $hall_name) {
|
foreach ($data['halls'] as $hall_name) {
|
||||||
?>
|
?>
|
||||||
<td><?php echo htmlspecialchars($hall_name[SCHED_LANG]); ?></td>
|
<td><?php echo htmlspecialchars($hall_name[$sched_config['lang']]); ?></td>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,21 +1,4 @@
|
||||||
<?php
|
<?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',
|
|
||||||
];
|
|
||||||
|
|
||||||
if (empty($allowedhallids)) {
|
|
||||||
$allowedhallids = array(6, 7, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
function compareKeys($a, $b, $key) {
|
function compareKeys($a, $b, $key) {
|
||||||
$valA = &$a[$key];
|
$valA = &$a[$key];
|
||||||
$valB = &$b[$key];
|
$valB = &$b[$key];
|
||||||
|
@ -23,9 +6,21 @@ function compareKeys($a, $b, $key) {
|
||||||
return ($valA < $valB) ? -1 : (($valA > $valB) ? 1 : 0);
|
return ($valA < $valB) ? -1 : (($valA > $valB) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [];
|
function loadData($config) {
|
||||||
|
$base_url = $config['cfp_url'] . '/api/conferences/2/';
|
||||||
|
|
||||||
foreach ($filenames as $name => $filename) {
|
$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);
|
$curl = new SmartCurl($base_url);
|
||||||
$json = $curl->getUrl($filename);
|
$json = $curl->getUrl($filename);
|
||||||
|
|
||||||
|
@ -61,14 +56,15 @@ foreach ($filenames as $name => $filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$data[$name] = $decoded;
|
$data[$name] = $decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
uasort($data['slots'], function($a, $b) {
|
uasort($data['slots'], function($a, $b) {
|
||||||
return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id');
|
return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id');
|
||||||
});
|
});
|
||||||
|
|
||||||
$data['halls'] = array_filter($data['halls'], function($key) use ($allowedhallids) {
|
$data['halls'] = array_filter($data['halls'], function($key) use ($config) {
|
||||||
return in_array($key, $allowedhallids);
|
return in_array($key, $config['allowedHallIds']);
|
||||||
}, ARRAY_FILTER_USE_KEY);
|
}, ARRAY_FILTER_USE_KEY);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
}
|
||||||
|
|
|
@ -1,31 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// 'halfnarp_friendly'
|
function parseData($config, $data) {
|
||||||
// 'events'
|
$time = 0;
|
||||||
// 'speakers'
|
$date = 0;
|
||||||
// 'tracks' [en/bg]
|
$lines = [];
|
||||||
// 'event_types' [en/bg]
|
$fulltalks = [];
|
||||||
// 'halls'
|
$prev_event_id = 0;
|
||||||
// 'slots'
|
$colspan = 1;
|
||||||
|
|
||||||
$data = require __DIR__ . DIRECTORY_SEPARATOR . 'load.php';
|
$languages = array(
|
||||||
|
|
||||||
if (!defined('SCHED_LANG')) {
|
|
||||||
define('SCHED_LANG', 'bg');
|
|
||||||
}
|
|
||||||
|
|
||||||
$cut_len = 70;
|
|
||||||
$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);
|
|
||||||
|
|
||||||
$languages = array(
|
|
||||||
'en' => array(
|
'en' => array(
|
||||||
'name' => 'English',
|
'name' => 'English',
|
||||||
'locale' => 'en_US.UTF8'
|
'locale' => 'en_US.UTF8'
|
||||||
|
@ -34,13 +16,17 @@ $languages = array(
|
||||||
'name' => 'Български',
|
'name' => 'Български',
|
||||||
'locale' => 'bg_BG.UTF8'
|
'locale' => 'bg_BG.UTF8'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/* We need to set these so we actually parse properly the dates. WP fucks up both. */
|
/* We need to set these so we actually parse properly the dates. WP fucks up both. */
|
||||||
date_default_timezone_set('Europe/Sofia');
|
date_default_timezone_set('Europe/Sofia');
|
||||||
setlocale(LC_TIME, $languages[SCHED_LANG]['locale']);
|
setlocale(LC_TIME, $languages[$config['lang']]['locale']);
|
||||||
|
|
||||||
|
foreach ($data['slots'] as $slot_id => $slot) {
|
||||||
|
if (!in_array($slot['hall_id'], $config['allowedHallIds'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($data['slots'] as $slot_id => $slot) {
|
|
||||||
$slotTime = $slot['starts_at'];
|
$slotTime = $slot['starts_at'];
|
||||||
$slotDate = date('d', $slotTime);
|
$slotDate = date('d', $slotTime);
|
||||||
|
|
||||||
|
@ -76,7 +62,7 @@ foreach ($data['slots'] as $slot_id => $slot) {
|
||||||
$lines[] = '<td>TBA</td>';
|
$lines[] = '<td>TBA</td>';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$title = mb_substr($event['title'], 0, $cut_len) . (mb_strlen($event['title']) > $cut_len ? '...' : '');
|
$title = mb_substr($event['title'], 0, $config['cut_len']) . (mb_strlen($event['title']) > $config['cut_len'] ? '...' : '');
|
||||||
$speakers = '';
|
$speakers = '';
|
||||||
|
|
||||||
if (count($event['participant_user_ids']) > 0) {
|
if (count($event['participant_user_ids']) > 0) {
|
||||||
|
@ -129,43 +115,43 @@ foreach ($data['slots'] as $slot_id => $slot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$prev_event_id = $slot['event_id'];
|
$prev_event_id = $slot['event_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines[] = '</tr>';
|
$lines[] = '</tr>';
|
||||||
|
|
||||||
/* create the legend */
|
/* create the legend */
|
||||||
$legend = [];
|
$legend = [];
|
||||||
|
|
||||||
foreach($data['tracks'] as $track) {
|
foreach($data['tracks'] as $track) {
|
||||||
$legend[] = '<tr><td class="' . $track['css_class'] . '">' . $track['name'][SCHED_LANG] . '</td></tr>';
|
$legend[] = '<tr><td class="' . $track['css_class'] . '">' . $track['name'][$config['lang']] . '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($languages as $code => $lang) {
|
foreach ($languages as $code => $lang) {
|
||||||
$legend[] = '<tr><td class="schedule-' . $code . '">' . $lang['name'] . '</td></tr>';
|
$legend[] = '<tr><td class="schedule-' . $code . '">' . $lang['name'] . '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$gspk = [];
|
$gspk = [];
|
||||||
$fspk = [];
|
$fspk = [];
|
||||||
$types = [];
|
$types = [];
|
||||||
$types['twitter']['url']='https://twitter.com/';
|
$types['twitter']['url']='https://twitter.com/';
|
||||||
$types['twitter']['class']='fa fa-twitter';
|
$types['twitter']['class']='fa fa-twitter';
|
||||||
$types['github']['url']='https://github.com/';
|
$types['github']['url']='https://github.com/';
|
||||||
$types['github']['class']='fa fa-github';
|
$types['github']['class']='fa fa-github';
|
||||||
$types['email']['url']='mailto:';
|
$types['email']['url']='mailto:';
|
||||||
$types['email']['class']='fa fa-envelope';
|
$types['email']['class']='fa fa-envelope';
|
||||||
|
|
||||||
$gspk[] = '<div class="grid members">';
|
$gspk[] = '<div class="grid members">';
|
||||||
|
|
||||||
foreach ($data['speakers'] as $speaker) {
|
foreach ($data['speakers'] as $speaker) {
|
||||||
$name = $speaker['first_name'] . ' ' . $speaker['last_name'];
|
$name = $speaker['first_name'] . ' ' . $speaker['last_name'];
|
||||||
|
|
||||||
$gspk[] = '<div class="member col4">';
|
$gspk[] = '<div class="member col4">';
|
||||||
$gspk[] = '<a href="#' . $name . '">';
|
$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[] = '<img width="100" height="100" src="' . $config['cfp_url'] . $speaker['picture']['schedule']['url'].'" class="attachment-100x100 wp-post-image" alt="' . $name .'" />';
|
||||||
$gspk[] = '</a> </div>';
|
$gspk[] = '</a> </div>';
|
||||||
|
|
||||||
$fspk[] = '<div class="speaker" id="' . $name . '">';
|
$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[] = '<img width="100" height="100" src="' . $config['cfp_url'] . $speaker['picture']['schedule']['url'].'" class="attachment-100x100 wp-post-image" alt="' . $name .'" />';
|
||||||
$fspk[] = '<h3>' . $name . '</h3>';
|
$fspk[] = '<h3>' . $name . '</h3>';
|
||||||
$fspk[] = '<div class="icons">';
|
$fspk[] = '<div class="icons">';
|
||||||
foreach ($types as $type => $parm) {
|
foreach ($types as $type => $parm) {
|
||||||
|
@ -176,8 +162,9 @@ foreach ($data['speakers'] as $speaker) {
|
||||||
$fspk[] = '</div>';
|
$fspk[] = '</div>';
|
||||||
$fspk[] = '<p>' . $speaker['biography'] . '</p>';
|
$fspk[] = '<p>' . $speaker['biography'] . '</p>';
|
||||||
$fspk[] = '</div><div class="separator"></div>';
|
$fspk[] = '</div><div class="separator"></div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$gspk[] = '</div>';
|
||||||
|
|
||||||
|
return compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend');
|
||||||
}
|
}
|
||||||
|
|
||||||
$gspk[] = '</div>';
|
|
||||||
|
|
||||||
return array_merge($data, compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend'));
|
|
||||||
|
|
Loading…
Reference in New Issue