function testFlattenHighlightWithOverlappingEntriesThatHaveEqualEnd()
 {
     $highlight1 = new Highlight(5, 10, Highlight::MATCH, 'ref1', 0, 0);
     $highlight2 = new Highlight(7, 10, Highlight::ADDED, 'ref2', 0, 0);
     $highlights = array($highlight1, $highlight2);
     $this->highlight->flattenHighlights($highlights);
     assertThat($highlights, anArray(array(new Highlight(5, 10, Highlight::UNDEFINED, 'ref1', 0, 0))));
 }
Exemplo n.º 2
0
 public function scanMonkFileRendered($tmpfname)
 {
     list($licenseIds, $highlights) = $this->scanMonk($tmpfname);
     $text = file_get_contents($tmpfname);
     $this->highlightProcessor->addReferenceTexts($highlights);
     $splitPositions = $this->highlightProcessor->calculateSplitPositions($highlights);
     $textFragment = new TextFragment(0, $text);
     $rendered = $this->textRenderer->renderText($textFragment, $splitPositions);
     return array($licenseIds, $rendered);
 }
Exemplo n.º 3
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param $licenseId
  * @param $selectedAgentId
  * @param $highlightId
  * @param int $clearingId
  * @param int $uploadId
  * @return Highlight[]
  */
 private function getSelectedHighlighting(ItemTreeBounds $itemTreeBounds, $licenseId, $selectedAgentId, $highlightId, $clearingId, $uploadId)
 {
     $unmaskAgents = $selectedAgentId;
     if (empty($selectedAgentId)) {
         $scanJobProxy = new ScanJobProxy($this->agentsDao, $uploadId);
         $scanJobProxy->createAgentStatus(array('nomos', 'monk', 'ninka'));
         $unmaskAgents = $scanJobProxy->getLatestSuccessfulAgentIds();
     }
     $highlightEntries = $this->highlightDao->getHighlightEntries($itemTreeBounds, $licenseId, $unmaskAgents, $highlightId, $clearingId);
     $groupId = Auth::getGroupId();
     if ($selectedAgentId > 0 || $clearingId > 0) {
         $this->highlightProcessor->addReferenceTexts($highlightEntries, $groupId);
     } else {
         $this->highlightProcessor->flattenHighlights($highlightEntries, array("K", "K "));
     }
     return $highlightEntries;
 }
Exemplo n.º 4
0
 /**
  * \brief Generate the view contents in HTML
  *
  * @param resource $inputFile
  * @param string $BackMod
  * @param int $ShowMenu
  * @param int $ShowHeader
  * @param null $ShowText
  * @param bool $ViewOnly
  * @param bool $DispView
  * @param Highlight[] $highlightEntries
  * @param bool $insertBacklink
  *
  * \note This function is intended to be called from other plugins.
  */
 function getView($inputFile = NULL, $BackMod = "browse", $ShowHeader = 1, $ShowText = NULL, $highlightEntries = array(), $insertBacklink = false, $getPageMenuInline = false)
 {
     if ($this->State != PLUGIN_STATE_READY) {
         $output = "Invalid plugin state: " . $this->State;
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $Upload = GetParm("upload", PARM_INTEGER);
     if (!empty($Upload) && !$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
         $output = "Access denied";
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $Item = GetParm("item", PARM_INTEGER);
     $Page = GetParm("page", PARM_INTEGER);
     $licenseId = GetParm("licenseId", PARM_INTEGER);
     if (!$inputFile && empty($Item)) {
         $output = "invalid input file";
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
     if ($ShowHeader) {
         $Uri = Traceback_uri() . "?mod=browse" . Traceback_parm_keep(array('item', 'show', 'folder', 'upload'));
         /* No item */
         $header = Dir2Browse($BackMod, $Item, NULL, $showBox = 0, "View", -1, '', '', $uploadtree_tablename);
         $this->vars['micromenu'] = $header;
     }
     /* Display file contents */
     $output = "";
     $openedFin = False;
     $Format = $this->microMenu->getFormatParameter($Item);
     if (empty($inputFile)) {
         $inputFile = @fopen(RepPathItem($Item), "rb");
         if ($inputFile) {
             $openedFin = true;
         }
         if (empty($inputFile)) {
             $output = $this->outputWhenFileNotInRepo($Upload, $Item);
             return $getPageMenuInline ? array("Error", $output) : $output;
         }
     }
     rewind($inputFile);
     $Uri = preg_replace('/&page=[0-9]*/', '', Traceback());
     $blockSize = $Format == 'hex' ? $this->blockSizeHex : $this->blockSizeText;
     if (!isset($Page) && !empty($licenseId)) {
         $startPos = -1;
         foreach ($highlightEntries as $highlightEntry) {
             if ($highlightEntry->getLicenseId() == $licenseId && ($startPos == -1 || $startPos > $highlightEntry->getStart())) {
                 $startPos = $highlightEntry->getStart();
             }
         }
         if ($startPos != -1) {
             $Page = floor($startPos / $blockSize);
         }
     }
     if (!empty($ShowText)) {
         echo $ShowText, "<hr>";
     }
     $PageMenu = $this->GetFileJumpMenu($inputFile, $Page, $blockSize, $Uri);
     $PageSize = $blockSize * $Page;
     if (!empty($PageMenu) and !$getPageMenuInline) {
         $output .= "<center>{$PageMenu}</center><br>\n";
     }
     $startAt = $PageSize;
     $endAt = $PageSize + $blockSize;
     $relevantHighlightEntries = array();
     foreach ($highlightEntries as $highlightEntry) {
         if ($highlightEntry->getStart() < $endAt && $highlightEntry->getEnd() >= $startAt) {
             $relevantHighlightEntries[] = $highlightEntry;
         }
     }
     $this->highlightProcessor->sortHighlights($relevantHighlightEntries);
     $splitPositions = $this->highlightProcessor->calculateSplitPositions($relevantHighlightEntries);
     if ($Format == 'hex') {
         $output .= $this->getHex($inputFile, $PageSize, $this->blockSizeHex, $splitPositions);
     } else {
         $output .= $this->getText($inputFile, $PageSize, $Format == 'text' ? 0 : 1, $this->blockSizeText, $splitPositions, $insertBacklink);
     }
     if (!empty($PageMenu) and !$getPageMenuInline) {
         $output .= "<P /><center>{$PageMenu}</center><br>\n";
     }
     if ($openedFin) {
         fclose($inputFile);
     }
     return $getPageMenuInline ? array($PageMenu, $output) : $output;
 }