Ejemplo n.º 1
0
 /**
  * @param $itemId
  * @return string
  */
 public function getFormatParameter($itemId = NULL)
 {
     $selectedFormat = GetParm("format", PARM_STRING);
     if (in_array($selectedFormat, $this->formatOptions)) {
         return $selectedFormat;
     }
     if (empty($itemId)) {
         return self::FORMAT_FLOW;
     } else {
         $mimeType = GetMimeType($itemId);
         list($type, $dummy) = explode("/", $mimeType, 2);
         return $type == 'text' ? self::FORMAT_TEXT : self::FORMAT_FLOW;
     }
 }
Ejemplo n.º 2
0
 /**
  * \brief Generate the view contents in HTML and sends it
  *  to stdout.
  *
  * \param $Name - the name for this plugin.
  * 
  * \note This function is intended to be called from other plugins.
  */
 function ShowView($Fin = NULL, $BackMod = "browse", $ShowMenu = 1, $ShowHeader = 1, $ShowText = NULL, $ViewOnly = False, $DispView = True)
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $V = "";
     global $Plugins;
     $Upload = GetParm("upload", PARM_INTEGER);
     if (!empty($Upload)) {
         $UploadPerm = GetUploadPerm($Upload);
         if ($UploadPerm < PERM_READ) {
             return;
         }
     }
     $Folder = GetParm("folder", PARM_INTEGER);
     $Show = GetParm("show", PARM_STRING);
     $Item = GetParm("item", PARM_INTEGER);
     $nomosagent_pk = GetParm("napk", PARM_INTEGER);
     $Page = GetParm("page", PARM_INTEGER);
     $bucketagent_pk = GetParm("bapk", PARM_INTEGER);
     if (!$Fin && (empty($Item) || empty($Upload))) {
         return;
     }
     if (empty($Page)) {
         $Page = 0;
     }
     /* Get uploadtree table name */
     $uploadtree_tablename = "uploadtree";
     if (!empty($Upload)) {
         $uploadtree_tablename = GetUploadtreeTablename($Upload);
     }
     switch (GetParm("format", PARM_STRING)) {
         case 'hex':
             $Format = 'hex';
             break;
         case 'text':
             $Format = 'text';
             break;
         case 'flow':
             $Format = 'flow';
             break;
         default:
             /* Determine default show based on mime type */
             if (empty($Item)) {
                 $Format = 'text';
             } else {
                 $Meta = GetMimeType($Item);
                 list($Type, $Junk) = explode("/", $Meta, 2);
                 if ($Type == 'text') {
                     $Format = 'flow';
                 } else {
                     switch ($Meta) {
                         case "application/octet-string":
                         case "application/x-awk":
                         case "application/x-csh":
                         case "application/x-javascript":
                         case "application/x-perl":
                         case "application/x-shellscript":
                         case "application/x-rpm-spec":
                         case "application/xml":
                         case "message/rfc822":
                             $Format = 'flow';
                             break;
                         default:
                             $Format = 'flow';
                     }
                 }
             }
             break;
     }
     /**********************************
        Display micro header
        **********************************/
     if ($ShowHeader) {
         $Uri = Traceback_uri() . "?mod=browse";
         $Opt = "";
         if (!empty($Item)) {
             $Opt .= "&item={$Item}";
         }
         if (!empty($Upload)) {
             $Opt .= "&upload={$Upload}";
         }
         if (!empty($Folder)) {
             $Opt .= "&folder={$Folder}";
         }
         if (!empty($Show)) {
             $Opt .= "&show={$Show}";
         }
         /* No item */
         $V .= Dir2Browse($BackMod, $Item, NULL, 1, "View", -1, '', '', $uploadtree_tablename) . "<P />\n";
     }
     // if ShowHeader
     $this->SortHighlightMenu();
     /***********************************
        Display file contents
        ***********************************/
     print $V;
     $V = "";
     $openedFin = False;
     if (empty($Fin)) {
         $Fin = @fopen(RepPathItem($Item), "rb");
         if ($Fin) {
             $openedFin = true;
         }
         if (empty($Fin)) {
             /* Added by vincent implement when view files which not in repository, ask user if want to reunpack*/
             /** BEGIN **/
             /* If this is a POST, then process the request. */
             $uploadunpack = GetParm('uploadunpack', PARM_INTEGER);
             $uploadpk = $Upload;
             $flag = 0;
             $P =& $Plugins[plugin_find_id("ui_reunpack")];
             $state = $P->CheckStatus($uploadpk, "reunpack", "ununpack");
             //print "<p>$state</p>";
             if ($state == 0 || $state == 2) {
                 if (!empty($uploadunpack)) {
                     $rc = $P->AgentAdd($uploadpk);
                     if (empty($rc)) {
                         /* Need to refresh the screen */
                         $text = _("Unpack added to job queue");
                         $V .= displayMessage($text);
                         $flag = 1;
                         $text = _("Reunpack job is running: you can see it in");
                         $text1 = _("jobqueue");
                         print "<p> <font color=red>{$text} <a href='" . Traceback_uri() . "?mod=showjobs'>{$text1}</a></font></p>";
                     } else {
                         $text = _("Unpack of Upload failed");
                         $V .= displayMessage("{$text}: {$rc}");
                     }
                     print $V;
                 }
             } else {
                 $flag = 1;
                 $text = _("Reunpack job is running: you can see it in");
                 $text1 = _("jobqueue");
                 print "<p> <font color=red>{$text} <a href='" . Traceback_uri() . "?mod=showjobs'>{$text1}</a></font></p>";
             }
             $text = _("File contents are not available in the repository.");
             print "{$text}\n";
             $P =& $Plugins[plugin_find_id("ui_reunpack")];
             print $P->ShowReunpackView($Item, $flag);
             return;
         }
         /** END **/
     }
     rewind($Fin);
     $Pages = "";
     $Uri = preg_replace('/&page=[0-9]*/', '', Traceback());
     $HighlightMenu = "";
     $HighlightMenu .= "</center>";
     // some fcn left a dangling center
     if ($Format == 'hex') {
         $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_HEX, $ViewOnly, $DispView);
         if (!empty($HighlightMenu)) {
             print "<center>{$HighlightMenu}</center><hr>\n";
         }
         $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_HEX, $Uri);
         $PageSize = VIEW_BLOCK_HEX * $Page;
         if (!empty($PageMenu)) {
             print "<center>{$PageMenu}</center><br>\n";
         }
         $this->ShowHex($Fin, $PageSize, VIEW_BLOCK_HEX);
         if (!empty($PageMenu)) {
             print "<P /><center>{$PageMenu}</center><br>\n";
         }
     } else {
         if ($Format == 'text') {
             $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_TEXT, $ViewOnly, $DispView);
             if (!empty($HighlightMenu)) {
                 print "<center>{$HighlightMenu}</center><hr>\n";
             }
             $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_TEXT, $Uri);
             $PageSize = VIEW_BLOCK_TEXT * $Page;
             if (!empty($PageMenu)) {
                 print "<center>{$PageMenu}</center><br>\n";
             }
             $this->ShowText($Fin, $PageSize, 0, VIEW_BLOCK_TEXT);
             if (!empty($PageMenu)) {
                 print "<P /><center>{$PageMenu}</center><br>\n";
             }
         } else {
             if ($Format == 'flow') {
                 $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_TEXT, $ViewOnly, $DispView);
                 if (!empty($HighlightMenu)) {
                     print "<center>{$HighlightMenu}</center><hr>\n";
                 }
                 $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_TEXT, $Uri);
                 $PageSize = VIEW_BLOCK_TEXT * $Page;
                 if (!empty($PageMenu)) {
                     print "<center>{$PageMenu}</center><br>\n";
                 }
                 if (!empty($ShowText)) {
                     echo $ShowText, "<hr>";
                 }
                 $this->ShowText($Fin, $PageSize, 1, VIEW_BLOCK_TEXT);
                 if (!empty($PageMenu)) {
                     print "<P /><center>{$PageMenu}</center><br>\n";
                 }
             }
         }
     }
     if ($openedFin) {
         fclose($Fin);
     }
     return;
 }