23 private $textRenderer;
25 private $highlightProcessor;
29 protected $blockSizeHex = 8192;
31 protected $blockSizeText = 81920;
35 $this->Name = self::NAME;
36 $this->Title = _(
"View File");
37 $this->Dependency = array(
"browse");
41 parent::__construct();
43 if (array_key_exists(
'BlockSizeHex', $GLOBALS[
'SysConf'][
'SYSCONFIG'])) {
44 $this->blockSizeHex =
max(64,
45 $GLOBALS[
'SysConf'][
'SYSCONFIG'][
'BlockSizeHex']);
47 if (array_key_exists(
'BlockSizeText', $GLOBALS[
'SysConf'][
'SYSCONFIG'])) {
48 $this->blockSizeText =
max(64,
49 $GLOBALS[
'SysConf'][
'SYSCONFIG'][
'BlockSizeText']);
53 $this->logger = $container->get(
"logger");
54 $this->textRenderer = $container->get(
"view.text_renderer");
55 $this->highlightProcessor = $container->get(
"view.highlight_processor");
56 $this->uploadDao = $container->get(
"dao.upload");
64 $tooltipText = _(
"View file contents");
65 menu_insert(
"Browse-Pfile::View", 10, $this->Name, $tooltipText);
69 $textFormat = $this->microMenu->getFormatParameter($itemId);
71 $this->microMenu->addFormatMenuEntries($textFormat, $pageNumber);
83 $tooltipText = _(
"View file contents");
84 $this->microMenu->insert(MicroMenu::TARGET_DEFAULT, $menuText, $menuPosition,
85 $this->Name, $this->Name . $URI, $tooltipText);
88 menu_insert(
"Browse::{$menuText}", - 2, $this->Name . $URI, $tooltipText);
104 $MaxSize = $Stat[
'size'];
105 $MaxPage = intval($MaxSize / $PageSize);
106 $V =
"<font class='text'>";
107 $CurrSize = $CurrPage * $PageSize;
111 if ($CurrPage * $PageSize >= $MaxSize) {
121 $V .=
"<a href='$Uri&page=0'>[$text]</a> ";
123 $V .=
"<a href='$Uri&page=" . ($CurrPage - 1) .
"'>[$text]</a> ";
126 for ($i = $CurrPage - 5; $i <= $CurrPage + 5; $i ++) {
127 if ($i == $CurrPage) {
128 $V .=
"<b>" . ($i + 1) .
"</b> ";
129 }
else if (($i >= 0) && ($i <= $MaxPage)) {
130 $V .=
"<a href='$Uri&page=$i'>" . ($i + 1) .
"</a> ";
133 if ($CurrPage < $MaxPage) {
135 $V .=
"<a href='$Uri&page=" . ($CurrPage + 1) .
"'>[$text]</a>";
137 $V .=
"<a href='$Uri&page=" . (intval(($MaxSize - 1) / $PageSize)) .
154 function ShowText($inputFile, $startOffset, $Flowed, $outputLength = -1,
155 $splitPositions =
null, $insertBacklink =
false)
158 $this->
getText($inputFile, $startOffset, $Flowed, $outputLength,
159 $splitPositions, $insertBacklink);
165 function getText($inputFile, $startOffset, $Flowed, $outputLength = -1,
166 $splitPositions =
null, $insertBacklink =
false, $fromRest =
false)
168 if (! ($outputLength = $this->checkAndPrepare($inputFile, $startOffset,
174 $output .= ($Flowed ?
'<div class="text">' :
'<div class="mono"><pre style="overflow:unset;">');
176 fseek($inputFile, $startOffset, SEEK_SET);
178 fread($inputFile, $outputLength));
180 $renderedText = $this->textRenderer->renderText($textFragment,
181 $splitPositions, $insertBacklink);
183 $output .= ($Flowed ? nl2br($renderedText) : $renderedText) .
184 (! $Flowed ?
"</pre>" :
"") .
"</div>\n";
186 return $fromRest ? $renderedText : $output;
193 function ShowHex($inputFile, $startOffset = 0, $outputLength = -1,
194 $splitPositions = array())
196 print $this->
getHex($inputFile, $startOffset, $outputLength, $splitPositions);
203 function getHex($inputFile, $startOffset = 0, $outputLength = -1,
204 $splitPositions = array())
206 if (! ($outputLength = $this->checkAndPrepare($inputFile, $startOffset,
212 fseek($inputFile, $startOffset, SEEK_SET);
214 fread($inputFile, $outputLength));
216 $output .=
"<div class='mono'>";
218 $renderedText = $this->textRenderer->renderHex($textFragment,
220 $output .= $renderedText;
222 $output .=
"</div>\n";
227 private function checkAndPrepare($inputFile, $startOffset, $outputLength)
233 $inputFileStat = fstat($inputFile);
234 $inputFileSize = $inputFileStat[
'size'];
236 if ($outputLength < 0) {
237 $outputLength = $inputFileSize;
240 if (($startOffset < 0) || ($startOffset >= $inputFileSize)) {
244 if ($outputLength == 0) {
247 return $outputLength;
266 function ShowView($inputFile =
null, $BackMod =
"browse", $ShowMenu = 1, $ShowHeader = 1,
267 $ShowText =
null, $ViewOnly =
false, $DispView =
true, $highlightEntries = array(),
268 $insertBacklink =
false)
270 return $this->
getView($inputFile, $BackMod, $ShowHeader, $ShowText,
271 $highlightEntries, $insertBacklink);
288 function getView($inputFile =
null, $BackMod =
"browse", $ShowHeader = 1, $ShowText =
null,
289 $highlightEntries = array(), $insertBacklink =
false, $getPageMenuInline =
false)
291 if ($this->
State != PLUGIN_STATE_READY) {
293 return $getPageMenuInline ? array(
"Error", $output) : $output;
297 if (! empty($Upload) &&
298 ! $this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
299 $output =
"Access denied";
300 return $getPageMenuInline ? array(
"Error", $output) : $output;
306 if (! $inputFile && empty($Item)) {
307 $output =
"invalid input file";
308 return $getPageMenuInline ? array(
"Error", $output) : $output;
311 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
317 $header =
Dir2Browse($BackMod, $Item,
null, $showBox = 0,
"View", - 1,
'',
318 '', $uploadtree_tablename);
319 $this->vars[
'micromenu'] = $header;
325 $Format = $this->microMenu->getFormatParameter($Item);
326 if (empty($inputFile)) {
331 if (empty($inputFile)) {
332 $output = $this->outputWhenFileNotInRepo($Upload, $Item);
333 return $getPageMenuInline ? array(
"Error", $output) : $output;
337 $Uri = preg_replace(
'/&page=[0-9]*/',
'',
Traceback());
339 $blockSize = $Format ==
'hex' ? $this->blockSizeHex : $this->blockSizeText;
341 if (! isset($Page) && ! empty($licenseId)) {
343 foreach ($highlightEntries as $highlightEntry) {
344 if ($highlightEntry->getLicenseId() == $licenseId &&
345 ($startPos == - 1 || $startPos > $highlightEntry->getStart())) {
346 $startPos = $highlightEntry->getStart();
349 if ($startPos != - 1) {
350 $Page = floor($startPos / $blockSize);
354 if (! empty($ShowText)) {
355 echo $ShowText,
"<hr>";
357 $PageMenu = $this->
GetFileJumpMenu($inputFile, $Page, $blockSize, $Uri);
358 $PageSize = $blockSize * $Page;
359 if (! empty($PageMenu) and ! $getPageMenuInline) {
360 $output .=
"<center>$PageMenu</center><br>\n";
363 $startAt = $PageSize;
364 $endAt = $PageSize + $blockSize;
365 $relevantHighlightEntries = array();
366 foreach ($highlightEntries as $highlightEntry) {
367 if ($highlightEntry->getStart() < $endAt &&
368 $highlightEntry->getEnd() >= $startAt) {
369 $relevantHighlightEntries[] = $highlightEntry;
373 $this->highlightProcessor->sortHighlights($relevantHighlightEntries);
375 $splitPositions = $this->highlightProcessor->calculateSplitPositions(
376 $relevantHighlightEntries);
378 if ($Format ==
'hex') {
379 $output .= $this->
getHex($inputFile, $PageSize, $this->blockSizeHex,
382 $output .= $this->
getText($inputFile, $PageSize, $Format ==
'text' ? 0 : 1,
383 $this->blockSizeText, $splitPositions, $insertBacklink);
386 if (! empty($PageMenu) and ! $getPageMenuInline) {
387 $output .=
"<P /><center>$PageMenu</center><br>\n";
394 return $getPageMenuInline ? array($PageMenu, $output) : $output;
401 protected function outputWhenFileNotInRepo($uploadpk, $item)
404 $reunpackPlugin = & $Plugins[plugin_find_id(
"ui_reunpack")];
405 $state = $reunpackPlugin->CheckStatus($uploadpk,
"reunpack",
"ununpack");
412 if ($state != 0 && $state != 2) {
414 $text = _(
"Reunpack job is running: you can see it in");
415 $text1 = _(
"jobqueue");
416 $output .=
"<p> <font color=red>$text <a href='" .
Traceback_uri() .
417 "?mod=showjobs'>$text1</a></font></p>";
418 } elseif (! empty($uploadunpack)) {
419 $rc = $reunpackPlugin->AgentAdd($uploadpk);
422 $this->vars[
'message'] = _(
"Unpack added to job queue");
424 $text = _(
"Reunpack job is running: you can see it in");
425 $text1 = _(
"jobqueue");
426 $output .=
"<p> <font color=red>$text <a href='" .
Traceback_uri() .
427 "?mod=showjobs'>$text1</a></font></p>";
429 $text = _(
"Unpack of Upload failed");
430 $this->vars[
'message'] =
"$text: $rc";
434 $text = _(
"File contents are not available in the repository.");
435 $output .=
"$text\n";
436 $output .= $reunpackPlugin->ShowReunpackView($item, $flag);
442 return $this->
ShowView(
null,
"browse");
447 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
getText($inputFile, $startOffset, $Flowed, $outputLength=-1, $splitPositions=null, $insertBacklink=false, $fromRest=false)
Given a file handle, display "strings" of the file.
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.
getHex($inputFile, $startOffset=0, $outputLength=-1, $splitPositions=array())
Given a file handle, display a "hex dump" of the file. Output goes to stdout!
GetFileJumpMenu($Fin, $CurrPage, $PageSize, $Uri)
Given a file handle and current page, generate the "Next" and "Prev" menu options....
ShowText($inputFile, $startOffset, $Flowed, $outputLength=-1, $splitPositions=null, $insertBacklink=false)
Given a file handle, display "strings" of the file. Output goes to stdout!
getView($inputFile=null, $BackMod="browse", $ShowHeader=1, $ShowText=null, $highlightEntries=array(), $insertBacklink=false, $getPageMenuInline=false)
Generate the view contents in HTML.
RegisterMenus()
Customize submenus.
Output()
This function is called when user output is requested. This function is responsible for content....
ShowHex($inputFile, $startOffset=0, $outputLength=-1, $splitPositions=array())
Given a file handle, display a "hex dump" of the file. Output goes to stdout!
__construct()
base constructor. Most plugins will just use this
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.
Traceback()
Get the URI + query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.