34 private $textRenderer;
36 private $highlightProcessor;
40 protected $blockSizeHex = 8192;
42 protected $blockSizeText = 81920;
44 function __construct()
46 $this->Name = self::NAME;
47 $this->Title = _(
"View File");
48 $this->Dependency = array(
"browse");
52 parent::__construct();
54 if (array_key_exists(
'BlockSizeHex', $GLOBALS[
'SysConf'][
'SYSCONFIG'])) {
55 $this->blockSizeHex =
max(64,
56 $GLOBALS[
'SysConf'][
'SYSCONFIG'][
'BlockSizeHex']);
58 if (array_key_exists(
'BlockSizeText', $GLOBALS[
'SysConf'][
'SYSCONFIG'])) {
59 $this->blockSizeText =
max(64,
60 $GLOBALS[
'SysConf'][
'SYSCONFIG'][
'BlockSizeText']);
64 $this->logger = $container->get(
"logger");
65 $this->textRenderer = $container->get(
"view.text_renderer");
66 $this->highlightProcessor = $container->get(
"view.highlight_processor");
67 $this->uploadDao = $container->get(
"dao.upload");
75 $tooltipText = _(
"View file contents");
76 menu_insert(
"Browse-Pfile::View", 10, $this->Name, $tooltipText);
80 $textFormat = $this->microMenu->getFormatParameter($itemId);
82 $this->microMenu->addFormatMenuEntries($textFormat, $pageNumber);
94 $tooltipText = _(
"View file contents");
95 $this->microMenu->insert(MicroMenu::TARGET_DEFAULT, $menuText, $menuPosition,
96 $this->Name, $this->Name . $URI, $tooltipText);
99 menu_insert(
"Browse::{$menuText}", - 2, $this->Name . $URI, $tooltipText);
115 $MaxSize = $Stat[
'size'];
116 $MaxPage = intval($MaxSize / $PageSize);
117 $V =
"<font class='text'>";
118 $CurrSize = $CurrPage * $PageSize;
122 if ($CurrPage * $PageSize >= $MaxSize) {
132 $V .=
"<a href='$Uri&page=0'>[$text]</a> ";
134 $V .=
"<a href='$Uri&page=" . ($CurrPage - 1) .
"'>[$text]</a> ";
137 for ($i = $CurrPage - 5; $i <= $CurrPage + 5; $i ++) {
138 if ($i == $CurrPage) {
139 $V .=
"<b>" . ($i + 1) .
"</b> ";
140 }
else if (($i >= 0) && ($i <= $MaxPage)) {
141 $V .=
"<a href='$Uri&page=$i'>" . ($i + 1) .
"</a> ";
144 if ($CurrPage < $MaxPage) {
146 $V .=
"<a href='$Uri&page=" . ($CurrPage + 1) .
"'>[$text]</a>";
148 $V .=
"<a href='$Uri&page=" . (intval(($MaxSize - 1) / $PageSize)) .
165 function ShowText($inputFile, $startOffset, $Flowed, $outputLength = -1,
166 $splitPositions = null, $insertBacklink =
false)
169 $this->
getText($inputFile, $startOffset, $Flowed, $outputLength,
170 $splitPositions, $insertBacklink);
176 function getText($inputFile, $startOffset, $Flowed, $outputLength = -1,
177 $splitPositions = null, $insertBacklink =
false)
179 if (! ($outputLength = $this->checkAndPrepare($inputFile, $startOffset,
185 $output .= ($Flowed ?
'<div class="text">' :
'<div class="mono"><pre>');
187 fseek($inputFile, $startOffset, SEEK_SET);
189 fread($inputFile, $outputLength));
191 $renderedText = $this->textRenderer->renderText($textFragment,
192 $splitPositions, $insertBacklink);
194 $output .= ($Flowed ? nl2br($renderedText) : $renderedText) .
195 (! $Flowed ?
"</pre>" :
"") .
"</div>\n";
204 function ShowHex($inputFile, $startOffset = 0, $outputLength = -1,
205 $splitPositions = array())
207 print $this->
getHex($inputFile, $startOffset, $outputLength, $splitPositions);
214 function getHex($inputFile, $startOffset = 0, $outputLength = -1,
215 $splitPositions = array())
217 if (! ($outputLength = $this->checkAndPrepare($inputFile, $startOffset,
223 fseek($inputFile, $startOffset, SEEK_SET);
225 fread($inputFile, $outputLength));
227 $output .=
"<div class='mono'>";
229 $renderedText = $this->textRenderer->renderHex($textFragment,
231 $output .= $renderedText;
233 $output .=
"</div>\n";
238 private function checkAndPrepare($inputFile, $startOffset, $outputLength)
244 $inputFileStat = fstat($inputFile);
245 $inputFileSize = $inputFileStat[
'size'];
247 if ($outputLength < 0) {
248 $outputLength = $inputFileSize;
251 if (($startOffset < 0) || ($startOffset >= $inputFileSize)) {
255 if ($outputLength == 0) {
258 return $outputLength;
277 function ShowView($inputFile = null, $BackMod =
"browse", $ShowMenu = 1, $ShowHeader = 1,
278 $ShowText = null, $ViewOnly =
false, $DispView =
true, $highlightEntries = array(),
279 $insertBacklink =
false)
281 return $this->
getView($inputFile, $BackMod, $ShowHeader, $ShowText,
282 $highlightEntries, $insertBacklink);
300 function getView($inputFile = null, $BackMod =
"browse", $ShowHeader = 1, $ShowText = null,
301 $highlightEntries = array(), $insertBacklink =
false, $getPageMenuInline =
false)
303 if ($this->
State != PLUGIN_STATE_READY) {
305 return $getPageMenuInline ? array(
"Error", $output) : $output;
309 if (! empty($Upload) &&
310 ! $this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
311 $output =
"Access denied";
312 return $getPageMenuInline ? array(
"Error", $output) : $output;
318 if (! $inputFile && empty($Item)) {
319 $output =
"invalid input file";
320 return $getPageMenuInline ? array(
"Error", $output) : $output;
323 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
329 $header =
Dir2Browse($BackMod, $Item, null, $showBox = 0,
"View", - 1,
'',
330 '', $uploadtree_tablename);
331 $this->vars[
'micromenu'] = $header;
337 $Format = $this->microMenu->getFormatParameter($Item);
338 if (empty($inputFile)) {
343 if (empty($inputFile)) {
344 $output = $this->outputWhenFileNotInRepo($Upload, $Item);
345 return $getPageMenuInline ? array(
"Error", $output) : $output;
349 $Uri = preg_replace(
'/&page=[0-9]*/',
'',
Traceback());
351 $blockSize = $Format ==
'hex' ? $this->blockSizeHex : $this->blockSizeText;
353 if (! isset($Page) && ! empty($licenseId)) {
355 foreach ($highlightEntries as $highlightEntry) {
356 if ($highlightEntry->getLicenseId() == $licenseId &&
357 ($startPos == - 1 || $startPos > $highlightEntry->getStart())) {
358 $startPos = $highlightEntry->getStart();
361 if ($startPos != - 1) {
362 $Page = floor($startPos / $blockSize);
366 if (! empty($ShowText)) {
367 echo $ShowText,
"<hr>";
369 $PageMenu = $this->
GetFileJumpMenu($inputFile, $Page, $blockSize, $Uri);
370 $PageSize = $blockSize * $Page;
371 if (! empty($PageMenu) and ! $getPageMenuInline) {
372 $output .=
"<center>$PageMenu</center><br>\n";
375 $startAt = $PageSize;
376 $endAt = $PageSize + $blockSize;
377 $relevantHighlightEntries = array();
378 foreach ($highlightEntries as $highlightEntry) {
379 if ($highlightEntry->getStart() < $endAt &&
380 $highlightEntry->getEnd() >= $startAt) {
381 $relevantHighlightEntries[] = $highlightEntry;
385 $this->highlightProcessor->sortHighlights($relevantHighlightEntries);
387 $splitPositions = $this->highlightProcessor->calculateSplitPositions(
388 $relevantHighlightEntries);
390 if ($Format ==
'hex') {
391 $output .= $this->
getHex($inputFile, $PageSize, $this->blockSizeHex,
394 $output .= $this->
getText($inputFile, $PageSize, $Format ==
'text' ? 0 : 1,
395 $this->blockSizeText, $splitPositions, $insertBacklink);
398 if (! empty($PageMenu) and ! $getPageMenuInline) {
399 $output .=
"<P /><center>$PageMenu</center><br>\n";
406 return $getPageMenuInline ? array($PageMenu, $output) : $output;
413 protected function outputWhenFileNotInRepo($uploadpk, $item)
416 $reunpackPlugin = & $Plugins[plugin_find_id(
"ui_reunpack")];
417 $state = $reunpackPlugin->CheckStatus($uploadpk,
"reunpack",
"ununpack");
424 if ($state != 0 && $state != 2) {
426 $text = _(
"Reunpack job is running: you can see it in");
427 $text1 = _(
"jobqueue");
428 $output .=
"<p> <font color=red>$text <a href='" .
Traceback_uri() .
429 "?mod=showjobs'>$text1</a></font></p>";
430 } elseif (! empty($uploadunpack)) {
431 $rc = $reunpackPlugin->AgentAdd($uploadpk);
434 $this->vars[
'message'] = _(
"Unpack added to job queue");
436 $text = _(
"Reunpack job is running: you can see it in");
437 $text1 = _(
"jobqueue");
438 $output .=
"<p> <font color=red>$text <a href='" .
Traceback_uri() .
439 "?mod=showjobs'>$text1</a></font></p>";
441 $text = _(
"Unpack of Upload failed");
442 $this->vars[
'message'] =
"$text: $rc";
446 $text = _(
"File contents are not available in the repository.");
447 $output .=
"$text\n";
448 $output .= $reunpackPlugin->ShowReunpackView($item, $flag);
452 public function Output()
454 return $this->
ShowView(null,
"browse");
459 $NewPlugin->Initialize();
getHex($inputFile, $startOffset=0, $outputLength=-1, $splitPositions=array())
Given a file handle, display a "hex dump" of the file. Output goes to stdout!
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
Traceback_uri()
Get the URI without query to this location.
GetFileJumpMenu($Fin, $CurrPage, $PageSize, $Uri)
Given a file handle and current page, generate the "Next" and "Prev" menu options. Returns String.
getView($inputFile=null, $BackMod="browse", $ShowHeader=1, $ShowText=null, $highlightEntries=array(), $insertBacklink=false, $getPageMenuInline=false)
Generate the view contents in HTML.
RegisterMenus()
Customize submenus.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
ShowHex($inputFile, $startOffset=0, $outputLength=-1, $splitPositions=array())
Given a file handle, display a "hex dump" of the file. Output goes to stdout!
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
ShowText($inputFile, $startOffset, $Flowed, $outputLength=-1, $splitPositions=null, $insertBacklink=false)
Given a file handle, display "strings" of the file. Output goes to stdout!
This is the Plugin class. All plugins should:
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
ShowView($inputFile=null, $BackMod="browse", $ShowMenu=1, $ShowHeader=1, $ShowText=null, $ViewOnly=false, $DispView=true, $highlightEntries=array(), $insertBacklink=false)
Generate the view contents in HTML and sends it to stdout.
getText($inputFile, $startOffset, $Flowed, $outputLength=-1, $splitPositions=null, $insertBacklink=false)
Given a file handle, display "strings" of the file.
Traceback()
Get the URI + query to this location.