How to output all pages in one long page?
Re: How to output all pages in one long page?
OK - got it. Changed the line in funtions.php - added the section to userfuncs.php - added <?php echo printlink();?> to the template (below content for test) - but no difference from normal print view, just the current page shows...
Notice: The print icon in the top blue line calls my own version of the print function - was the only way I could figure out to show the Font Awesome print icon and make it clickable to print...
Notice: The print icon in the top blue line calls my own version of the print function - was the only way I could figure out to show the Font Awesome print icon and make it clickable to print...
Re: How to output all pages in one long page?
Hm, https://sk.egmont-hs.dk/?1.-H%C3%B8jsko ... orie&print appears to be fine (i.e. as expected).Korvell wrote:but no difference from normal print view, just the current page shows...
I'm not sure, though, if you want to always display all pages in the print view.
Christoph M. Becker – Plugins for CMSimple_XH
Re: How to output all pages in one long page?
Wow - that does work indeed - although your link only shows sektion 1. But if I simply put in a direkt link for "http://sk.egmont-hs.dk/index.php?print" it shows the whole site from the top level. But now I get an error 404 at the top - the rest of the site shows up nicely. So close now...
Re: How to output all pages in one long page?
Well, that was pretty surprising for me! The cause is, that ?print is regarded as page name, but as no such page exists, a 404 is printed by content() but the submenu shows all pages. Compare that with https://sk.egmont-hs.dk/index.php?&print, which shows the expected behavior.Korvell wrote:But if I simply put in a direkt link for "http://sk.egmont-hs.dk/index.php?print" it shows the whole site from the top level. But now I get an error 404 at the top - the rest of the site shows up nicely.
Anyhow, if you want to always show all pages in the print view, just use the following in cmsimple/userfuncs.php:
Code: Select all
<?php
class ExpandedSubmenu
{
private $pages;
public function __construct()
{
$this->pages = new XH_Pages;
}
public function render()
{
global $print, $s;
$html = '';
$old_s = $s;
foreach ($this->pages->toplevels() as $page) {
if (!$this->pages->isHidden($page)) {
$html .= $this->renderPage($page);
}
}
$s = $old_s;
return $html;
}
private function renderPage($index)
{
global $c, $s;
$s = $index;
$html = XH_convertPrintUrls(evaluate_scripting($c[$index]));
foreach ($this->pages->children($index) as $page) {
$html .= $this->renderPage($page);
}
return $html;
}
}
function submenu_print()
{
return (new ExpandedSubmenu)->render();
}
Code: Select all
submenu_print(), '</body>', "\n", '</html>', "\n";
Last edited by cmb on Wed Aug 09, 2017 9:05 pm, edited 1 time in total.
Reason: Fixed code wrt. hidden pages
Reason: Fixed code wrt. hidden pages
Christoph M. Becker – Plugins for CMSimple_XH
Re: How to output all pages in one long page?
Actually - I would like to have both options: Print current page and print all pages That was my initially thoughts when I looked for that internal CMSimple command from old ages...
Re: How to output all pages in one long page?
OK - changed the userfuncs.php and now the printout looks better - but still got an issue: the first page shows twice
Re: How to output all pages in one long page?
Update: Seems there might have been a cache problem because now the print works well - no double page 1. But - and I hate to say it - there's still an issue - hidden page titles (the H1 ones) shows up. Guess this is a wink to maybe switch to 1.7.0 eventually.
Thank You all, especially Christoph. Always a pleasure to witness the expertise in this forum.
PS: If it's not too much trouble - any suggestion how to have two print functions - one for all and one for current page?
Thank You all, especially Christoph. Always a pleasure to witness the expertise in this forum.
PS: If it's not too much trouble - any suggestion how to have two print functions - one for all and one for current page?
Re: How to output all pages in one long page?
There may be a difference when logged in as admin or not. If the first page is duplicated, check the modifications in functions.php; the output of content() or $content should be removed.Korvell wrote:Update: Seems there might have been a cache problem because now the print works well - no double page 1
Oh, indeed, I've overlooked that. I have fixed the code above now (only the userfuncs.php part has to be updated).Korvell wrote:But - and I hate to say it - there's still an issue - hidden page titles (the H1 ones) shows up.
If all necessary plugins are compatible with XH 1.7.0, I'd suggest to upgrade as soon as possible.Korvell wrote:Guess this is a wink to maybe switch to 1.7.0 eventually.
Do you want two different functions, or just one function which works differently for the first page only (i.e. show all pages for the first page, but only subpages for all other pages)?Korvell wrote:PS: If it's not too much trouble - any suggestion how to have two print functions - one for all and one for current page?
Christoph M. Becker – Plugins for CMSimple_XH
Re: How to output all pages in one long page?
Thanks. Now it works perfectly - I indeed had forgotten to remove "$content" from the line in functions.php.
My wish for the function is two separate functions; one that takes current page only and one that takes all. I think it would be confusing for the visitor if the print button would work differently depending on what pages he was displaying. I do understand that would require two buttons/links - one for each option - on the page.
I agree that in this current project that probably no one wishes to just print the first page, but I could vision other projects of mine to have much more on the first page that you would only want to print that specific page and not all. So - two functions . Or maybe it could actually be just one with optional parameter call of what to print?
Thanks so much again for all the help.
My wish for the function is two separate functions; one that takes current page only and one that takes all. I think it would be confusing for the visitor if the print button would work differently depending on what pages he was displaying. I do understand that would require two buttons/links - one for each option - on the page.
I agree that in this current project that probably no one wishes to just print the first page, but I could vision other projects of mine to have much more on the first page that you would only want to print that specific page and not all. So - two functions . Or maybe it could actually be just one with optional parameter call of what to print?
Thanks so much again for all the help.
Re: How to output all pages in one long page?
Okay, makes sense. I've also noticed an issue with XH 1.7 where changing XH_builtinTemplate() as described above would make login impossible. Furthermore, it doesn't make sense to show this "printlink" on special pages (such as ?sitemap). So I've reworked the code; the following has to be put into cmsimple/userfuncs.php:Korvell wrote:Or maybe it could actually be just one with optional parameter call of what to print?
Code: Select all
<?php
class XPrint
{
private $pages;
public function __construct()
{
$this->pages = new XH_Pages;
}
public function dispatch($all, $text)
{
global $s;
if ($s < 0) {
return;
}
if (isset($_GET['xprint'])) {
$this->render($_GET['xprint'] === 'all');
} else {
return a($s, '&xprint=' . ($all ? 'all' : 'sub')) . $text . '</a>';
}
}
private function render($all)
{
global $sl, $cf, $_XH_csrfProtection;
while (ob_get_level()) {
ob_end_clean();
}
if ($cf['xhtml']['endtags'] == 'true') {
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"',
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n",
'<html xmlns="http://www.w3.org/1999/xhtml"',
(strlen($sl) == 2 ? " lang=\"$sl\" xml:lang=\"$sl\"" : ''), '>', "\n";
} else {
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"',
' "http://www.w3.org/TR/html4/loose.dtd">', "\n", '<html',
(strlen($sl) == 2 ? " lang=\"$sl\"" : ''), '>', "\n";
}
$content = XH_convertPrintUrls($this->renderContent($all));
echo '<head>', "\n" . head(),
tag('meta name="robots" content="noindex"'), "\n",
'</head>', "\n", '<body class="', $bodyClass,'"', onload(), '>', "\n",
$content, '</body>', "\n", '</html>', "\n";
if (isset($_XH_csrfProtection)) {
$_XH_csrfProtection->store();
}
exit;
}
private function renderContent($all)
{
global $print, $s;
$html = '';
$old_s = $s;
if ($all) {
foreach ($this->pages->toplevels() as $page) {
if (!$this->pages->isHidden($page)) {
$html .= $this->renderPage($page);
}
}
} else {
$html .= $this->renderPage($s);
foreach ($this->pages->children($s) as $page) {
$html .= $this->renderPage($page);
}
}
$s = $old_s;
return $html;
}
private function renderPage($index)
{
global $c, $s;
$s = $index;
$html = XH_convertPrintUrls(evaluate_scripting($c[$index]));
foreach ($this->pages->children($index) as $page) {
$html .= $this->renderPage($page);
}
return $html;
}
}
function xprint($all, $text)
{
return (new XPrint)->dispatch($all, $text);
}
Code: Select all
<?php echo xprint(true, 'print all pages')?>
<?php echo xprint(false, 'print page with subpages')?>
Code: Select all
<?php echo xprint(true, $tx['template']['text1']?>
Last edited by cmb on Fri Aug 11, 2017 9:55 am, edited 1 time in total.
Reason: Fix wrong example calls
Reason: Fix wrong example calls
Christoph M. Becker – Plugins for CMSimple_XH