diff --git a/schedule/class.SmartCurl.php b/schedule/class.SmartCurl.php index b963a31..6ebda1c 100644 --- a/schedule/class.SmartCurl.php +++ b/schedule/class.SmartCurl.php @@ -71,17 +71,16 @@ class SmartCurl { } if (curl_setopt($this->ch, CURLOPT_URL, $url) === false) { - throw new Exception('set url failed'); + throw new Exception('set url failed: ' . $url); } - $cache_file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename; - + $cache_file = $this->cache_dir . DIRECTORY_SEPARATOR . str_replace('/', '@', $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'); + throw new Exception('set etag failed: ' . $url); } $response = curl_exec($this->ch); @@ -123,12 +122,6 @@ class SmartCurl { $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); } diff --git a/schedule/config.php b/schedule/config.php index d0ab77b..3cdc9ee 100644 --- a/schedule/config.php +++ b/schedule/config.php @@ -5,11 +5,28 @@ function getSchedConfig($year = 2015) { 'cfp_url' => 'https://cfp.openfest.org', 'cut_len' => 70, ]; - + $config = [ + 2014 => [ + 'conferenceId' => 1, + 'eventTypes' => [ + 'lecture' => 1, + 'workshop' => 2, + ], + ], 2015 => [ - 'allowedHallIds' => [6, 7, 8], - + 'conferenceId' => 2, + 'eventTypes' => [ + 'lecture' => 3, + 'workshop' => 4, + ], + ], + 2016 => [ + 'conferenceId' => 3, + 'eventTypes' => [ + 'lecture' => 5, + 'workshop' => 6, + ], ], ]; diff --git a/schedule/index.php b/schedule/index.php index ba026a3..a8739d9 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -43,24 +43,14 @@ foreach ($content['lines'] as $line) {
diff --git a/schedule/load.php b/schedule/load.php index 2466763..a33769a 100644 --- a/schedule/load.php +++ b/schedule/load.php @@ -7,8 +7,6 @@ function compareKeys($a, $b, $key) { } function loadData($config) { - $base_url = $config['cfp_url'] . '/api/conferences/2/'; - $filenames = [ 'events' => 'events.json', 'speakers' => 'speakers.json', @@ -19,10 +17,10 @@ function loadData($config) { ]; $data = []; - + $curl = new SmartCurl($config['cfp_url'] . '/api/conferences/'); + foreach ($filenames as $name => $filename) { - $curl = new SmartCurl($base_url); - $json = $curl->getUrl($filename); + $json = $curl->getUrl($config['conferenceId'] . '/' . $filename); if ($json === false) { echo 'get failed: ', $filename, PHP_EOL; @@ -62,9 +60,5 @@ function loadData($config) { return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id'); }); - $data['halls'] = array_filter($data['halls'], function($key) use ($config) { - return in_array($key, $config['allowedHallIds']); - }, ARRAY_FILTER_USE_KEY); - return $data; } diff --git a/schedule/parse.php b/schedule/parse.php index f195336..6ded92b 100644 --- a/schedule/parse.php +++ b/schedule/parse.php @@ -3,7 +3,7 @@ function parseData($config, $data) { $time = 0; $date = 0; $lines = []; - $fulltalks = []; + $fulltalks = ''; $prev_event_id = 0; $colspan = 1; @@ -22,11 +22,7 @@ function parseData($config, $data) { date_default_timezone_set('Europe/Sofia'); 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) { $slotTime = $slot['starts_at']; $slotDate = date('d', $slotTime); @@ -77,7 +73,7 @@ function parseData($config, $data) { } else { /* TODO: fix the URL */ $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; - $spk[$uid] = '' . $name . ''; + $spk[$uid] = '' . $name . ''; } } $speakers = implode (', ', $spk); @@ -86,9 +82,9 @@ function parseData($config, $data) { /* 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']; + $csslang = 'schedule-' . $event['language']; } else { - $csslang = ""; + $csslang = ''; } $cssclass = &$data['tracks'][$event['track_id']]['css_class']; $style = ' class="' . $cssclass . ' ' . $csslang . '"'; @@ -96,13 +92,12 @@ function parseData($config, $data) { /* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */ - $fulltalks[$eid] = ''; - $fulltalks[$eid] .= '
'; + $fulltalks .= '
'; /* We don't want '()' when we don't have a speaker name */ $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; - $fulltalks[$eid] .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; - $fulltalks[$eid] .= '

' . $event['abstract'] . '

'; - $fulltalks[$eid] .= '
'; + $fulltalks .= '

' . $event['title'] . ' ' . $fulltalk_spkr . '

'; + $fulltalks .= '

' . $event['abstract'] . '

'; + $fulltalks .= '
'; if ($slot['event_id'] === $prev_event_id) { array_pop($lines); @@ -120,51 +115,58 @@ function parseData($config, $data) { $lines[] = ''; /* create the legend */ - $legend = []; + $legend = ''; foreach($data['tracks'] as $track) { - $legend[] = '' . $track['name'][$config['lang']] . ''; + $legend .= '' . $track['name'][$config['lang']] . ''; } foreach ($languages as $code => $lang) { - $legend[] = '' . $lang['name'] . ''; + $legend .= '' . $lang['name'] . ''; } - $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[] = '
'; + $gspk = '
'; + $fspk = ''; + $types = [ + 'twitter' => [ + 'class' => 'twitter', + 'url' => 'https://twitter.com/', + ], + 'github' => [ + 'class' => 'github', + 'url' => 'https://github.com/', + ], + 'email' => [ + 'class' => 'envelope', + 'url' => 'mailto:', + ], + ]; foreach ($data['speakers'] as $speaker) { $name = $speaker['first_name'] . ' ' . $speaker['last_name']; - $gspk[] = ''; + $gspk .= ''; - $fspk[] = '
'; - $fspk[] = '' . $name .''; - $fspk[] = '

' . $name . '

'; - $fspk[] = '
'; - foreach ($types as $type => $parm) { + $fspk .= '
'; + $fspk .= '' . $name .''; + $fspk .= '

' . $name . '

'; + $fspk .= '
'; + + foreach ($types as $type => $param) { if (!empty($speaker[$type])) { - $fspk[] = ''; + $fspk .= ''; } } - $fspk[] = '
'; - $fspk[] = '

' . $speaker['biography'] . '

'; - $fspk[] = '
'; + + $fspk .= '
'; + $fspk .= '

' . $speaker['biography'] . '

'; + $fspk .= '
'; } - $gspk[] = '
'; + $gspk .= '
'; return compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend'); }