<?
require_once('class.plakat.php');
define('IMAGE_WIDTH', 10000);
define('IMAGE_HEIGHT', 10000);
class HtmlPlakat extends Plakat
{
var $data;
var $curr;
var $currId;
function HtmlPlakat()
{
$this->Plakat(10, 20, 30);
}
function createHtml($ids, $showYear = false)
{
if (!is_array($ids))
{
$ids = array($ids);
}
$this->data = array();
$this->drawPage($ids, IMAGE_WIDTH, count($ids) * IMAGE_HEIGHT, 500, 0, 0, count($ids) * 3, 1, $showYear, true);
// save the last item to the data array
$this->_nextItem();
$output='<link href="assets/templates/html_plakat.css" rel="stylesheet">';
/*css is in file now*/
/*
$output = '<style type="text/css">
table.kktable {
width: 580px;
}
table.kkitem {
width: 100%;
}
table.kkitem td {
padding-bottom: 5px;
}
table.kkgroup {
}
table.kkgroup td {
padding: 0px;
padding-right: 10px;
}
.kktable h1, .kktable td, .kktable span {
font-family: Verdana,sans-serif;
}
.kktable h1 {
font-weight: bold;
font-size: 13px;
border: solid 1px black;
border-bottom: solid 2px black;
padding: 3px;
margin-top: 5px;
margin-bottom: 0px;
}
.kk30 {
font-weight: bold;
font-size: 16px;
}
.kk10 {
font-size: 11px;
}
.kktable hr {
border: solid 1px black;
}
</style>';
*/
$output .= '<table cellpadding="0" cellspacing="0" border="0" class="kktable"><tr><td>';
$output .= "\n";
foreach ($this->data as $concertId => $item)
{
reset($item);
list($firstKey, $firstItem) = each($item);
if ($firstItem == 'line')
{
$title = '<hr />';
}
else
{
$title = '<h1>'.$firstItem[0]['text'].'</h1>';
}
unset($item[$firstKey]);
$groups = array();
$groupIdx = -1;
$lastY = -1000;
foreach ($item as $y => $line)
{
if ($y - $lastY > 50)
{
$groupIdx++;
}
$lineSize = -1;
foreach ($line as $x => $part)
{
if ($lineSize < 0 || $lineSize == $part['size'])
{
$lineSize = $part['size'];
}
else
{
// add "follow" flag for all parts that are not the same size
// as the first part of the same line. This means it will
// follow immediately the previous text without going into
// a new cell
$line[$x]['follow'] = true;
}
}
$lastY = $y;
$groups[$groupIdx][$y] = $line;
}
$output .= '<a name="k'.$concertId.'"></a>';
$output .= '<table cellpadding="0" cellspacing="0" border="0" class="kkitem">';
$output .= '<tr><td>'.$title.'</td></tr></table>';
$output .= '<table cellpadding="0" cellspacing="0" border="0" class="kkitem"><tr><td>';
//$this->debug($groups);
foreach ($groups as $g => $group)
{
if ($g > 0)
{
$output .= '</td></tr><tr><td>';
}
$output .= '<table cellpadding="0" cellspacing="0" border="0" class="kkgroup">';
//$this->debug($group);
$xPositions = array();
$xPositions[] = 0; // ensure a column at position 0
$grid = array();
foreach ($group as $y => $line)
{
foreach ($line as $x => $cell)
{
if (!isset($cell['follow']))
{
$grid[$y][$x]['texts'][] = $cell;
$grid[$y][$x]['size'] = $cell['size'];
$prevX = $x;
if (!in_array($x, $xPositions))
{
$xPositions[] = $x;
}
}
else
{
$grid[$y][$prevX]['texts'][] = $cell;
$grid[$y][$prevX]['multisize'] = true;
}
//$this->debug(array('x' => $x, 'y' => $y, 'cell' => $cell));
}
}
sort($xPositions);
//$this->debug($xPositions);
//$this->debug($grid);
foreach ($grid as $y => $line)
{
$colSpan = 0;
$lastX = 100;
for ($i = count($xPositions) - 1; $i >= 0; $i--)
{
$x = $xPositions[$i];
$colSpan++;
if (isset($grid[$y][$x]))
{
$grid[$y][$x]['span'] = $colSpan;
//$grid[$y][$x]['width'] = ($lastX - $x).'%';
$colSpan = 0;
$lastX = $x;
}
}
if ($colSpan > 0)
{
$grid[$y][$xPositions[0]] = array('span' => $colSpan, 'size' => 10);
}
ksort($grid[$y]);
$output .= '<tr>';
foreach ($grid[$y] as $x => $cell)
{
// $cell = {texts?, size?, multisize?, span}
$multiSize = @$cell['multisize'];
$cellSize = @$cell['size'];
$output .= '<td nowrap="nowrap" valign="top"';
if ($cell['span'] > 1)
{
$output .= ' colspan="'.$cell['span'].'"';
}
if (!$multiSize && $cellSize)
{
$output .= ' class="kk'.$cellSize.'"';
}
$output .= '>';
//$this->debug($cell['lines']);
if (isset($cell['texts']))
{
foreach ($cell['texts'] as $part)
{
//var_dump($output);
//$this->debug($part);
if ($multiSize)
{
$output .= '<span class="kk'.$part['size'].'">';
}
# $output .= str_replace('(tel)', '☏'/*'<img src="admin/images/tel.png" />'*/, $part['text']);
$output .= str_replace('(tel)', '<font size="3">✆</font>'/*'<img src="admin/images/tel.png" />'*/, $part['text']);
if ($multiSize)
{
$output .= '</span>';
}
}
}
else
{
$output .= ' ';
}
$output .= '</td>';
}
$output .= '</tr>';
}
$output .= '</table>';
//$this->debug($grid);
}
$flyerFile = '/home/www/web60/html/admin/upload/'.$concertId.'.pdf';
$output .= "<!-- $flyerFile -->";
if (!isset($_SESSION['cug']) && file_exists($flyerFile))
{
$fileSize = (int) (filesize($flyerFile) / 1024);
$output .= "</td></tr><tr><td class=\"kk10\"><a href=\"/admin/upload/$concertId.pdf\" target=\"_blank\">Mehr Informationen</a> (PDF, $fileSize kB)";
}
$output .= "</td></tr></table>\n";
$query = 'SELECT logo_url, logo_link
FROM mk_vereine
WHERE verein_id = (
SELECT konzert_verein
FROM mk_konzerte
WHERE konzert_id ='.$concertId.')';
$result = $this->db->safeQuery($query);
while ($row = mysql_fetch_assoc($result)) {
$logo_url=$row["logo_url"];
$logo_link=$row["logo_link"];
/*<div class='fb-like' data-href='".$urlik."' data-layout='standard' data-action='like' data-show-faces='false' data-share='true'></div>*/
if ($logo_url!='' && $logo_link!='') {
//echo '1<br>';
$output .= "<div class='logoimg'><a href='".$logo_link."'><img src='".$logo_url."'/></a></div>
<div id='share_on_facebook".$concertId."'><span class='pluginButtonLabel'>Share</span></div>
<script>
jQuery(function() {
jQuery('#share_on_facebook".$concertId."').click(function() {
FB.ui(
{
method: 'feed',
name: '".$title."',
link: 'http://konzerte-bern.ch/".$_SERVER['REQUEST_URI']."',
description: '".$this->tagsToSpaces($output)."',
picture:'http://konzerte-bern.ch/".$logo_url."'
},
function(response) {
if (response && !response.error_code) {
alert('Posting completed.');
} else {
alert('Error while posting.');
}
}
);
});});
</script>";
//$output = '';
}
/*<div class='fb-like' data-href='".$urlik."' data-layout='standard' data-action='like' data-show-faces='false' data-share='true'></div>*/
//$this->debug($this->data);
if ($logo_url!='' && $logo_link=='') {
// echo '2<br>';
$output .= "<div class='logoimg'><img src='".$logo_url."'/></div>
<div id='share_on_facebook".$concertId."'><span class='pluginButtonLabel'>Share</span></div>
<script>
jQuery(function() {
jQuery('#share_on_facebook".$concertId."').click(function() {
FB.ui(
{
method: 'feed',
name: '".$title."',
link: 'http://konzerte-bern.ch/".$_SERVER['REQUEST_URI']."',
description: '".$this->tagsToSpaces($output)."',
picture:'http://konzerte-bern.ch/".$logo_url."'
},
function(response) {
if (response && !response.error_code) {
alert('Posting completed.');
} else {
alert('Error while posting.');
}
}
);
});});
</script>";
//$output = '';
}
/*
if ($logo_url=='' && $logo_link=='') {
//echo '3<br>';
$output .="<div id='share_on_facebook".$concertId."'><span class='pluginButtonLabel'>Share</span></div>
<script>
jQuery(function() {
jQuery('#share_on_facebook".$concertId."').click(function() {
FB.ui(
{
method: 'feed',
name: '".$title."',
link: 'http://konzerte-bern.ch/".$_SERVER['REQUEST_URI']."',
description: '".$this->tagsToSpaces($output)."',
picture:''
},
function(response) {
if (response && !response.error_code) {
alert('Posting completed.');
} else {
alert('Error while posting.');
}
}
);
});});
</script>";
}
*/
}
}
$output .= "</td></tr></table>";
$output = $this->parseLinks($output);
return $output;
}
function parseLinks($str)
{
$str = str_replace('www.', 'http://www.', $str);
$str = preg_replace('|http://([a-zA-Z0-9-\./\?=_]+)|', '<a href="http://$1" target="_blank">$1</a>', $str);
$str = preg_replace('/(([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6})/', '<a href="mailto:$1">$1</a>', $str);
$str = preg_replace("/(<script>(.*?(\\n))+.*?link: \')((<a href=\"(.*)\")(.*,))((.*?(\\n))+.*?<\/script>)/U",'${1}$6\',${8}',$str);
$str = preg_replace("/(<script>(.*?(\\n))+.*?picture:\')((<a href=\"(.*)\")(.*'))((.*?(\\n))+.*?<\/script>)/U",'${1}$6\'${8}',$str);
$str = preg_replace("/((<script>(.*?(\\n))+.*?description: '(.*?(\\n))+.*?)(<a href=\"(.*))\"(.*?(\\n))+.*?)((.*?(\\n))+.*?<\/script>)/U",'${2}$8\',${11}',$str);
$str = preg_replace("/( )/U",'',$str);
$str = preg_replace("/(<script>(.*?(\\n))+.*?description: ')(\\s*)(\\w(.*?(\\n))+.*?<\/script>)/U",'${1}${5}',$str);
return $str;
}
//function added by kazak1377 17.09.2014 replecing all html tags by space
function tagsToSpaces($str) {
//$str = preg_replace("/(<\/tr>)/U",',',$str);
$str = preg_replace("/(<.*>)/U",' ',$str);
//$str=ltrim($str);
return $str;
}
function debug($mixed)
{
echo "<pre>";
print_r($mixed);
echo "</pre>";
}
function drawSingleItem($id, $width, $height, $x = 0, $y = 0, $dayHeader = true)
{
$this->_nextItem($id);
return Plakat::drawSingleItem($id, $width, $height, $x, $y, $dayHeader);
}
function drawText($x, $y, $text, $size, $border = false) // y = lower left position of the text
{
// this method must return the width of the drawn text
$this->curr[$y][$x] = array('text' => $text, 'size' => $size, 'border' => $border);
return $this->measureText($text, $size);
}
function drawLine($x1, $y1, $x2, $y2)
{
$this->curr[$y1] = 'line';
return 99;
}
function measureText($text, $size)
{
// this method must return the width of the text
return strlen($text);
}
function getLineHeight($size)
{
// this method must return the line height for a certain font size
return $size;
}
function _nextItem($id = 0)
{
if (count($this->curr))
{
$this->data[$this->currId] = $this->curr;
}
$this->currId = $id;
$this->curr = array();
}
}
?>