本文整理汇总了PHP中HTMLWriter::generateInlineHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP HTMLWriter::generateInlineHeaders方法的具体用法?PHP HTMLWriter::generateInlineHeaders怎么用?PHP HTMLWriter::generateInlineHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLWriter
的用法示例。
在下文中一共展示了HTMLWriter::generateInlineHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: switchAction
public function switchAction($action, $httpVars, $filesVars)
{
$repository = ConfService::getRepositoryById($httpVars["repository_id"]);
if (!$repository->detectStreamWrapper(true)) {
return false;
}
if (AuthService::usersEnabled()) {
$loggedUser = AuthService::getLoggedUser();
if ($loggedUser === null && ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth")) {
AuthService::logUser("guest", null);
$loggedUser = AuthService::getLoggedUser();
}
if (!$loggedUser->canSwitchTo($repository->getId())) {
echo "You do not have permissions to access this resource";
return false;
}
}
$selection = new UserSelection($repository, $httpVars);
if ($action == "open_file") {
$selectedNode = $selection->getUniqueNode();
$selectedNodeUrl = $selectedNode->getUrl();
if (!file_exists($selectedNodeUrl) || !is_readable($selectedNodeUrl)) {
echo "File does not exist";
return false;
}
$filesize = filesize($selectedNodeUrl);
$fp = fopen($selectedNodeUrl, "rb");
$fileMime = "application/octet-stream";
//Get mimetype with fileinfo PECL extension
if (class_exists("finfo")) {
$finfo = new finfo(FILEINFO_MIME);
$fileMime = $finfo->buffer(fread($fp, 2000));
}
//Get mimetype with (deprecated) mime_content_type
if (strpos($fileMime, "application/octet-stream") === 0 && function_exists("mime_content_type")) {
$fileMime = @mime_content_type($fp);
}
//Guess mimetype based on file extension
if (strpos($fileMime, "application/octet-stream") === 0) {
$fileExt = substr(strrchr(basename($selectedNodeUrl), '.'), 1);
if (empty($fileExt)) {
$fileMime = "application/octet-stream";
} else {
$regex = "/^([\\w\\+\\-\\.\\/]+)\\s+(\\w+\\s)*({$fileExt}\\s)/i";
$lines = file($this->getBaseDir() . "/resources/other/mime.types");
foreach ($lines as $line) {
if (substr($line, 0, 1) == '#') {
continue;
}
// skip comments
$line = rtrim($line) . " ";
if (!preg_match($regex, $line, $matches)) {
continue;
}
// no match to the extension
$fileMime = $matches[1];
}
}
}
fclose($fp);
// If still no mimetype, give up and serve application/octet-stream
if (empty($fileMime)) {
$fileMime = "application/octet-stream";
}
//Send headers
HTMLWriter::generateInlineHeaders(basename($selectedNodeUrl), $filesize, $fileMime);
$stream = fopen("php://output", "a");
AJXP_MetaStreamWrapper::copyFileInStream($selectedNodeUrl, $stream);
fflush($stream);
fclose($stream);
AJXP_Controller::applyHook("node.read", array($selectedNode));
$this->logInfo('Download', 'Read content of ' . $selectedNodeUrl, array("files" => $selectedNodeUrl));
}
}
示例2: applyActions
public function applyActions($actionName, $httpVars, $fileVars)
{
$git = new VersionControl_Git($this->repoBase);
switch ($actionName) {
case "git_history":
$file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
$file = ltrim($file, "/");
$res = $this->gitHistory($git, $file);
AJXP_XMLWriter::header();
$ic = AJXP_Utils::mimetype($file, "image", false);
$index = count($res);
$mess = ConfService::getMessages();
foreach ($res as &$commit) {
unset($commit["DETAILS"]);
$commit["icon"] = $ic;
$commit["index"] = $index;
$commit["EVENT"] = $mess["meta.git." . $commit["EVENT"]];
$index--;
AJXP_XMLWriter::renderNode("/" . $commit["ID"], basename($commit["FILE"]), true, $commit);
}
AJXP_XMLWriter::close();
break;
break;
case "git_revertfile":
$originalFile = AJXP_Utils::decodeSecureMagic($httpVars["original_file"]);
$file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
$commitId = $httpVars["commit_id"];
$command = $git->getCommand("cat-file");
$command->setOption("s", true);
$command->addArgument($commitId . ":" . $file);
$size = $command->execute();
$command = $git->getCommand("show");
$command->addArgument($commitId . ":" . $file);
$commandLine = $command->createCommandString();
$outputStream = fopen($this->repoBase . $originalFile, "w");
$this->executeCommandInStreams($git, $commandLine, $outputStream);
fclose($outputStream);
$this->commitChanges();
AJXP_XMLWriter::header();
AJXP_XMLWriter::reloadDataNode();
AJXP_XMLWriter::close();
break;
case "git_getfile":
$file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
$commitId = $httpVars["commit_id"];
$attach = $httpVars["attach"];
$command = $git->getCommand("cat-file");
$command->setOption("s", true);
$command->addArgument($commitId . ":" . $file);
$size = $command->execute();
$command = $git->getCommand("show");
$command->addArgument($commitId . ":" . $file);
$commandLine = $command->createCommandString();
if ($attach == "inline") {
$fileExt = substr(strrchr(basename($file), '.'), 1);
if (empty($fileExt)) {
$fileMime = "application/octet-stream";
} else {
$regex = "/^([\\w\\+\\-\\.\\/]+)\\s+(\\w+\\s)*({$fileExt}\\s)/i";
$lines = file(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/editor.browser/resources/other/mime.types");
foreach ($lines as $line) {
if (substr($line, 0, 1) == '#') {
continue;
}
// skip comments
$line = rtrim($line) . " ";
if (!preg_match($regex, $line, $matches)) {
continue;
}
// no match to the extension
$fileMime = $matches[1];
}
}
if (empty($fileMime)) {
$fileMime = "application/octet-stream";
}
HTMLWriter::generateInlineHeaders(basename($file), $size, $fileMime);
} else {
HTMLWriter::generateAttachmentsHeader(basename($file), $size, false, false);
}
$outputStream = fopen("php://output", "a");
$this->executeCommandInStreams($git, $commandLine, $outputStream);
fclose($outputStream);
break;
break;
default:
break;
}
}
示例3: switchAction
public function switchAction($action, $httpVars, $filesVars)
{
if (!isset($this->actions[$action])) {
return false;
}
$repository = ConfService::getRepositoryById($httpVars["repository_id"]);
if (!$repository->detectStreamWrapper(true)) {
return false;
}
if (AuthService::usersEnabled()) {
$loggedUser = AuthService::getLoggedUser();
if ($loggedUser === null && ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth")) {
AuthService::logUser("guest", null);
$loggedUser = AuthService::getLoggedUser();
}
if (!$loggedUser->canSwitchTo($repository->getId())) {
echo "You do not have permissions to access this resource";
return false;
}
}
$streamData = $repository->streamData;
$destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
if ($action == "open_file") {
$file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
if (!file_exists($destStreamURL . $file)) {
echo "File does not exist";
return false;
}
$filesize = filesize($destStreamURL . $file);
$fp = fopen($destStreamURL . $file, "rb");
//Get mimetype with fileinfo PECL extension
if (class_exists("finfo")) {
$finfo = new finfo(FILEINFO_MIME);
$fileMime = $finfo->buffer(fread($fp, 100));
} elseif (function_exists("mime_content_type")) {
$fileMime = @mime_content_type($fp);
} else {
$fileExt = substr(strrchr(basename($file), '.'), 1);
if (empty($fileExt)) {
$fileMime = "application/octet-stream";
} else {
$regex = "/^([\\w\\+\\-\\.\\/]+)\\s+(\\w+\\s)*({$fileExt}\\s)/i";
$lines = file($this->getBaseDir() . "/resources/other/mime.types");
foreach ($lines as $line) {
if (substr($line, 0, 1) == '#') {
continue;
}
// skip comments
$line = rtrim($line) . " ";
if (!preg_match($regex, $line, $matches)) {
continue;
}
// no match to the extension
$fileMime = $matches[1];
}
}
}
fclose($fp);
// If still no mimetype, give up and serve application/octet-stream
if (empty($fileMime)) {
$fileMime = "application/octet-stream";
}
//Send headers
HTMLWriter::generateInlineHeaders(basename($file), $filesize, $fileMime);
$class = $streamData["classname"];
$stream = fopen("php://output", "a");
call_user_func(array($streamData["classname"], "copyFileInStream"), $destStreamURL . $file, $stream);
fflush($stream);
fclose($stream);
exit(1);
}
}