Commit d40e8181 authored by Taddeus Kroes's avatar Taddeus Kroes

Allowed image tags in details, centered details window properly

parent a36f743c
<?php <?php
function clean_tag_content($text) {
return htmlentities($text, ENT_COMPAT | ENT_HTML5 | ENT_SUBSTITUTE, 'ISO-8859-1');
}
function clean_html($html) {
$html = preg_replace('/\s+/', ' ', $html);
$in_tag = false;
$stack = '';
$cleaned = '';
for ($i = 0, $l = strlen($html); $i < $l; $i++) {
switch ($html[$i]) {
case '<':
$in_tag = true;
$cleaned .= clean_tag_content($stack) . '<';
$stack = '';
break;
case '>':
$in_tag = false;
$cleaned .= '>';
break;
default:
if ($in_tag)
$cleaned .= $html[$i];
else
$stack .= $html[$i];
}
}
$cleaned .= $stack;
return $cleaned;
}
// Fetch details page
assert(isset($_GET['id'])); assert(isset($_GET['id']));
assert(is_numeric($_GET['id'])); assert(is_numeric($_GET['id']));
$url = 'http://www.tvgids.nl/programma/' . $_GET['id']; $url = 'http://www.tvgids.nl/programma/' . $_GET['id'];
$page = file_get_contents($url); $page = file_get_contents($url);
// Parse detailed description, preserving a selected set of HTML tags
preg_match('/<div\s+id="prog-content">\s*(.*?)\s*<div\s+class="prog-functionbar">/s', $page, $m1); preg_match('/<div\s+id="prog-content">\s*(.*?)\s*<div\s+class="prog-functionbar">/s', $page, $m1);
assert($m1); assert($m1);
$description = strip_tags($m1[1], '<p><strong><em><b><i><font><a><span>'); $description = strip_tags($m1[1], '<p><strong><em><b><i><font><a><span><img>');
$description = str_replace('showVideoPlaybutton()', '', $description); $description = str_replace('showVideoPlaybutton()', '', $description);
$description = preg_replace('/\s+/', ' ', $description); $description = clean_html($description);
$description = htmlentities($description, ENT_COMPAT | ENT_HTML5 | ENT_SUBSTITUTE, 'ISO-8859-1'); //$description = preg_replace('/\s+/', ' ', $description);
$description = str_replace(array('&lt;', '&gt;', '&sol;'), array('<', '>', '/'), $description); //$description = htmlentities($description, ENT_COMPAT | ENT_HTML5 | ENT_SUBSTITUTE, 'ISO-8859-1');
//$description = str_replace(array('&lt;', '&gt;', '&sol;'), array('<', '>', '/'), $description);
// Parse properties list
preg_match('/<ul\s+id="prog-info-content-colleft">\s*(.*?)\s*<\/ul>/s', $page, $m2); preg_match('/<ul\s+id="prog-info-content-colleft">\s*(.*?)\s*<\/ul>/s', $page, $m2);
assert($m2); assert($m2);
preg_match_all('/<li><strong>(\w+):<\/strong>(.*?)<\/li>/', $m2[1], $m3); preg_match_all('/<li><strong>(\w+):<\/strong>(.*?)<\/li>/', $m2[1], $m3);
...@@ -21,4 +61,5 @@ foreach ($m3[1] as $i => $name) ...@@ -21,4 +61,5 @@ foreach ($m3[1] as $i => $name)
$properties[] = array('name' => $name, 'value' => $m3[2][$i]); $properties[] = array('name' => $name, 'value' => $m3[2][$i]);
echo json_encode(compact('description', 'properties'), JSON_UNESCAPED_SLASHES); echo json_encode(compact('description', 'properties'), JSON_UNESCAPED_SLASHES);
?> ?>
...@@ -221,6 +221,10 @@ ProgramDetailsView = Backbone.View.extend( ...@@ -221,6 +221,10 @@ ProgramDetailsView = Backbone.View.extend(
$('#loading-screen').hide() $('#loading-screen').hide()
@$el.show() @$el.show()
@$('.content').html(@template(_.extend(id: id, data))) @$('.content').html(@template(_.extend(id: id, data)))
# Vertically align in middle
top = @$('.content').outerHeight() / 2
@$('.content').css(marginTop: "-#{top}px")
) )
else else
@$el.hide() @$el.hide()
......
...@@ -252,7 +252,8 @@ $loader-size: 66px ...@@ -252,7 +252,8 @@ $loader-size: 66px
margin: (-$loader-size / 2) 0 0 (-$loader-size / 2) margin: (-$loader-size / 2) 0 0 (-$loader-size / 2)
background: url("loading.gif") no-repeat left top background: url("loading.gif") no-repeat left top
$details-width: 480px $details-width: 500px
$details-initial-offset: 150px
.program-details .content .program-details .content
position: absolute position: absolute
...@@ -260,12 +261,15 @@ $details-width: 480px ...@@ -260,12 +261,15 @@ $details-width: 480px
top: 50% top: 50%
left: 50% left: 50%
width: $details-width width: $details-width
margin: -150px 0 0 (-$details-width / 2) margin: -$details-initial-offset 0 0 (-$details-width / 2)
border-radius: 6px border-radius: 6px
padding: 10px 15px padding: 10px 15px
font: 12px/18px Helvetica font: 12px/18px Helvetica
box-shadow: 0 0 7px 5px #0f0f0f box-shadow: 0 0 7px 5px #0f0f0f
*
max-width: $details-width
.properties .properties
padding-left: 15px padding-left: 15px
margin-top: 1px margin-top: 1px
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment