FOSSology  4.4.0
Open Source License Compliance by Open Source Software
HighlightRenderer.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2015 Siemens AG
4  Authors: Andreas Würl, Daniele Fognini
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 namespace Fossology\Lib\View;
10 
13 
19 {
20  const DEFAULT_PADDING = 0;
21 
22  public $classMapping = array('' => '',
23  Highlight::UNDEFINED=>'hi-undefined',
24 
25  Highlight::MATCH => 'hi-match',
26  Highlight::CHANGED => 'hi-changed',
27  Highlight::ADDED => 'hi-added',
28  Highlight::DELETED => 'hi-deleted',
29  Highlight::SIGNATURE => 'hi-signature',
30  Highlight::KEYWORD => 'hi-keyword',
31  Highlight::BULK => 'hi-bulk',
32  Highlight::COPYRIGHT => 'hi-cp',
33  Highlight::EMAIL => 'hi-email',
34  Highlight::URL => 'hi-url',
35  Highlight::AUTHOR => 'hi-author',
36  Highlight::BULK => 'hi-bulk',
37  Highlight::IPRA => 'hi-ipra',
38  Highlight::ECC => 'hi-mediumorchid',
39  Highlight::KEYWORDOTHERS => 'hi-teal'
40  );
41 
46  public function createSpanStart(SplitPosition &$entry)
47  {
48  $depth = $entry->getLevel();
49  $highlight = $entry->getHighlight();
50  $type = $highlight ? $highlight->getType() : Highlight::UNDEFINED;
51 
52  $wrappendElement = "";
53 
54  if ($highlight) {
55  $htmlElement = $highlight->getHtmlElement();
56  if ($htmlElement) {
57  $wrappendElement = $htmlElement->getOpeningText();
58  }
59  }
60 
61  return $this->createStyleWithPadding($type, $highlight->getInfoText(), $depth) . $wrappendElement;
62  }
63 
68  public function createSpanEnd(SplitPosition $entry)
69  {
70  $highlight = $entry->getHighlight();
71 
72  $wrappendElement = "";
73 
74  if ($highlight) {
75  $htmlElement = $highlight->getHtmlElement();
76  if ($htmlElement) {
77  $wrappendElement = $htmlElement->getClosingText();
78  }
79  }
80 
81  return $wrappendElement . '</span>';
82  }
83 
90  public function createStyleWithPadding($type, $title, $depth = 0)
91  {
92  $style = $this->createStartSpan($type, $title);
93  if ($depth < self::DEFAULT_PADDING) {
94  $padd = (2 * (self::DEFAULT_PADDING - $depth - 2)) . 'px';
95  return $this->getStyleWithPadding($padd, $style);
96  } else {
97  return $style;
98  }
99  }
100 
107  public function getStyleWithPadding($padding, $style)
108  {
109  return str_replace('background', "padding-top:$padding;padding-bottom:$padding;background", $style);
110  }
111 
117  public function createStartSpan($type, $title)
118  {
119  if ($type == 'K ' || $type == 'K') {
120  return "<span class=\"hi-keyword\">";
121  }
122  if (! array_key_exists($type, $this->classMapping)) {
123  $type = Highlight::UNDEFINED;
124  }
125  $class = $this->classMapping[$type];
126  return "<span class=\"$class\" title=\"$title\">";
127  }
128 
133  public function getLegendData($containsDiff)
134  {
135  $data = array();
136 
137  $colorDefinition = $containsDiff
138  ? array(
139  '' => _('license text:'),
140  Highlight::MATCH => _('&nbsp;- identical'),
141  Highlight::CHANGED => _('&nbsp;- modified'),
142  Highlight::ADDED => _('&nbsp;- added'),
143  Highlight::DELETED => _('&nbsp;- removed'),
144  Highlight::SIGNATURE => _('license relevant text'),
145  Highlight::KEYWORD => _('keyword'),
146  Highlight::BULK => _('bulk'))
147  : array(
148  Highlight::UNDEFINED => _("license relevant text"));
149  foreach ($colorDefinition as $colorKey => $txt) {
150  $data[] = array('class'=>$this->classMapping[$colorKey], 'text' => $txt);
151  }
152  return $data;
153  }
154 }
createStyleWithPadding($type, $title, $depth=0)