FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
HighlightRenderer.php
1 <?php
2 /*
3 Copyright (C) 2014-2015, Siemens AG
4 Authors: Andreas Würl, Daniele Fognini
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 namespace Fossology\Lib\View;
21 
24 
30 {
31  const DEFAULT_PADDING = 0;
32 
33  public $classMapping = array('' => '',
34  Highlight::UNDEFINED=>'hi-undefined',
35 
36  Highlight::MATCH => 'hi-match',
37  Highlight::CHANGED => 'hi-changed',
38  Highlight::ADDED => 'hi-added',
39  Highlight::DELETED => 'hi-deleted',
40  Highlight::SIGNATURE => 'hi-signature',
41  Highlight::KEYWORD => 'hi-keyword',
42  Highlight::BULK => 'hi-bulk',
43  Highlight::COPYRIGHT => 'hi-cp',
44  Highlight::EMAIL => 'hi-email',
45  Highlight::URL => 'hi-url',
46  Highlight::AUTHOR => 'hi-author',
47  Highlight::BULK => 'hi-bulk',
48  Highlight::IP => 'hi-ip',
49  Highlight::ECC => 'hi-mediumorchid'
50  );
51 
56  public function createSpanStart(SplitPosition &$entry)
57  {
58  $depth = $entry->getLevel();
59  $highlight = $entry->getHighlight();
60  $type = $highlight ? $highlight->getType() : Highlight::UNDEFINED;
61 
62  $wrappendElement = "";
63 
64  if ($highlight) {
65  $htmlElement = $highlight->getHtmlElement();
66  if ($htmlElement) {
67  $wrappendElement = $htmlElement->getOpeningText();
68  }
69  }
70 
71  return $this->createStyleWithPadding($type, $highlight->getInfoText(), $depth) . $wrappendElement;
72  }
73 
78  public function createSpanEnd(SplitPosition $entry)
79  {
80  $highlight = $entry->getHighlight();
81 
82  $wrappendElement = "";
83 
84  if ($highlight) {
85  $htmlElement = $highlight->getHtmlElement();
86  if ($htmlElement) {
87  $wrappendElement = $htmlElement->getClosingText();
88  }
89  }
90 
91  return $wrappendElement . '</span>';
92  }
93 
100  public function createStyleWithPadding($type, $title, $depth = 0)
101  {
102  $style = $this->createStartSpan($type, $title);
103  if ($depth < self::DEFAULT_PADDING) {
104  $padd = (2 * (self::DEFAULT_PADDING - $depth - 2)) . 'px';
105  return $this->getStyleWithPadding($padd, $style);
106  } else {
107  return $style;
108  }
109  }
110 
117  public function getStyleWithPadding($padding, $style)
118  {
119  return str_replace('background', "padding-top:$padding;padding-bottom:$padding;background", $style);
120  }
121 
127  public function createStartSpan($type, $title)
128  {
129  if ($type == 'K ' || $type == 'K') {
130  return "<span class=\"hi-keyword\">";
131  }
132  if (! array_key_exists($type, $this->classMapping)) {
133  $type = Highlight::UNDEFINED;
134  }
135  $class = $this->classMapping[$type];
136  return "<span class=\"$class\" title=\"$title\">";
137  }
138 
143  public function getLegendData($containsDiff)
144  {
145  $data = array();
146 
147  $colorDefinition = $containsDiff
148  ? array(
149  '' => _('license text:'),
150  Highlight::MATCH => _('&nbsp;- identical'),
151  Highlight::CHANGED => _('&nbsp;- modified'),
152  Highlight::ADDED => _('&nbsp;- added'),
153  Highlight::DELETED => _('&nbsp;- removed'),
154  Highlight::SIGNATURE => _('license relevant text'),
155  Highlight::KEYWORD => _('keyword'),
156  Highlight::BULK => _('bulk'))
157  : array(
158  Highlight::UNDEFINED => _("license relevant text"));
159  foreach ($colorDefinition as $colorKey => $txt) {
160  $data[] = array('class'=>$this->classMapping[$colorKey], 'text' => $txt);
161  }
162  return $data;
163  }
164 }
createStyleWithPadding($type, $title, $depth=0)