Change the Browser title - zend-framework

I am using links to display PDF files. I wish to show the PDF in a new tab so I add target="_blank". This works fine. A new tab is opened but I wish to change the title of the tab.
The link redirects me to this controller code as follows:-
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
#readfile($file);
The pdf is displayed correctly but there is no view script so I have no control via the script. Is there a header("Browser title: ???") I can use?
TIA Effy

For this problem, I use this trick:
I use a simple html page with an iframe like this:
<html>
<head>
<title>Your PDF Title</title>
<link type="image/x-icon" rel="icon" href="">
</head>
<body>
<iframe src="/module/controller/action/param..." id="ifrm" name="ifrm" width="100%" height="100%">
</iframe>
</body>
</html>
The iframe contains the PDF and the page has title.
Of course, you can use javascript to have a dynamic title

The internal pdfviewer in Firefox seems to fetch the title of the document from the metadata in the pdf.
With for instance Zend_Pdf this metadata can be manipulated.
$title = 'My custom title';
$pdf = Zend_Pdf::load($filepath);
$metadata = $pdf->getMetadata();
$metadataDOM = new DOMDocument();
$metadataDOM->loadXML($metadata);
$domTitle = $metadataDOM->getElementsByTagName('title')->item(0);
$domTitle->nodeValue = $title;
$pdf->setMetadata($metadataDOM->saveXML());
//maybe old style document info:
$pdf->properties['Title'] = $title;//this didn't work for me
echo $pdf->render();
I'm no DOM manipulation expert, but this worked for me with a file created with Illustrator CS5. Freely based on the Zend Framework Documentation. You might need to do some error checking along the way.

Related

css and js file path change when clicking other page in codeigniter

I have working stylesheet in my codeigniter homepage but if i click on another page the file path also change. that's one reason why my stylsheet not working on other page
the filepath loke like this:
localhost/foldernam/controller_name/stylesheet.css
is there any way that if i visit on other page filepath be remain?
i just want the filepath should be like this
localhost/foldernam/stylesheet.css
in my config.php
$config['base_url'] = 'http://localhost/systems/';
add base_url variabel when you include stylesheet.css, for example
<link rel="stylesheet" type="text/css" href="<?= base_url() . "stylesheet.css" ?>">
Add this code on header your html layout

how to render javascript source code in sapui5

I want to render some javascript snippet with sapui5. I am trying to use Text control but when I use that I cannt format javascript text to show up properly.Is there a way to do that?
You can use the HTML core control to embed html/javascript: https://sapui5.hana.ondemand.com/sdk/#docs/api/symbols/sap.ui.core.HTML.html
Or create a custom control
All other SAPUI5 controls are protected against XSS and forgery attacks so they won't accept any javascript code.
I also suggest that you use sap.ui.core.HTML to embed HTML in your sapui5 view. However to get your code formatted correctly (for example it shall be indented correctly) you can use the markdown-js library. See this example:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>Render javascript source code in sapui5</title>
<script id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.ui.commons"></script>
<script src="markdown.js"></script>
<script>
$.get("markdown.md", function(data) {
var mdView = new sap.ui.core.HTML({
content: markdown.toHTML(data)
});
mdView.placeAt("uiArea");
}, "html");
</script>
</head>
<body class="sapUiBody">
<div id="uiArea"></div>
</body>
</html>
markdown.md:
# Markdown
To produce a code block in Markdown, simply indent every line of the block by at least 4 spaces or 1 tab.
for (i=0; i < 10; i++) {
if (true) {
console.log("Hello World!");
}
}
If you want to test this example in you Chrome browser, do the following:
Download markdown-browser-*.tgz from markdown-js and place the contained markdown.js together with the above index.html and markdown.md in some folder.
Start Chrome with parameter --allow-file-access-from-files and drop the index.html on the Chrome browser window.

need to replace a link in content pulled with file_get_contents & base url

I am using file_get_contents to pull content from an external page. I then use a base tag to fix all broken links and paths. This works perfectly, However, I have javascript tabs in that page with anchor tags that look like this href="#". Problem is, the tab urls are also affected by the base url tag. When you click on it, it opens the tab but also sends you right back to the external page. Can I use a preg_replace to replace all href="#" with href="http://domain.com/page.php#" to fix the tab links? How will I add it to this code of mine?
<?php
$url = 'http://www.externaldomain.com';
$data = file_get_contents($url);
$data = '<head><base href='.$url.' target="_blank" /></head>'.$data;
echo $data;
?>
Try something like this:
$data = preg_replace('/\bhref="#"/', 'href="http://domain.com/page.php#"', $data);
Just replace the href="#" attributes with your desired ones.

Tiny MCE Default Content

I want to load TinyMCe with default content as below when loaded .
<html>
<body>
</body>
</html>
I have set cleanup : false . Still it wraps html with <p></p> and removes my code .
Any solution to this ?
Got it solved . Just had to enable full html plugin.

Perl Dancer Template headers, footers

I'm learning Perl and using Dancer as a web framework.
I've got two views (tt files) which should share the same navigation.
So, it would be great to start learning how to manage templates for navigation and footers.
I've read the documentation for the Template Toolkit and I've done the following:
I've changed the config.yml file to:
#template: "simple"
template: "template_toolkit"
engines:
template_toolkit:
start_tag: '[%'
end_tag: '%]'
I've defined the templates in the .pm file:
package proyecto;
use Dancer ':syntax';
our $VERSION = '0.1';
get '/' => sub {
template 'index';
};
get '/menu' => sub {
template 'menu';
};
true;
There is a link in the index template directing the visitor to the menu template:
<li class="active">< a href="/menu">Menu <span class="sr-only"></span></a></li>
I would like to reuse the navigation code from index.tt into menu.tt, so I've wrapped the navigation code in index.tt with the following:
[% BLOCK navigation %]
#my nav code
[% END %]
To finally include that code in the menu.tt file, I've written the following (where the navigation code should be):
[% navigation = 'index.tt' %]
[% INCLUDE navigation %]
The files index.tt and menu.tt are located in the folder views. But it seems it's not that easy! =( Any suggestion on how to reuse code from one file to another which is located in the same directory?
This is what layouts are for. The idea is that content common to all pages (e.g. header, footer, navbar) goes in the layout and content specific to each page goes in templates called views. Views are called "partials" in other frameworks because they only contain the content for part of the page.
If you use the dancer command line utility to set up your application, the default layout is views/layouts/main.tt and looks something like this:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=<% settings.charset %>" />
<title>Foo</title>
<link rel="stylesheet" href="<% request.uri_base %>/css/style.css" />
</head>
<body>
<% content %>
<div id="footer">
Powered by Dancer <% dancer_version %>
</div>
</body>
</html>
The <% content %> section is replaced with the specified view when you call template 'view';. (In your case, you'll need to change <% and %> to [% and %] since you're using the Template Toolkit-style delimiters.)
For example, if views/index.tt is:
<h1>Hello, World!</h1>
calling template 'index'; in a route renders the following:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Foo</title>
<link rel="stylesheet" href="http://www.example.com/css/style.css" />
</head>
<body>
<h1>Hello, World!</h1>
<div id="footer">
Powered by Dancer 1.3202
</div>
</body>
</html>
Note that there's already a footer section; you just have to add elements for a header and navbar.
If this is new development, you should really be using Dancer2 instead of Dancer (fortunately, layouts and views are the same in both).
The [% INCLUDE %] directive's argument can be interpreted in one of two ways.
The name of another template file
The name of a block that is defined in the current template file (or in another template file which has included the current template file).
All of which means that your current plan won't work. menu.tt won't see any block defined inside index.tt.
There are a couple of better solutions though.
Firstly, consider moving the navigation code into a third, separate, template file. You can then INCLUDE this template into both index.tt and menu.tt.
Secondly, you can use Dancer's "layout" feature. This is a template that is wrapped around your view templates. Typically the layout template contains the navigation and all standard page furniture (like headers and footers). It also contains a [% content %] directive. When a view is rendered, the rendered version is dropped into the layout template in the location of the [% content %] directive. See the Layouts section in Dancer::Tutorial for more information.
p.s. I see you're using Dancer. I'd highly recommend switching to Dancer2.