Name

capture_page — process page and save output to file and/or scratch variable

ATTRIBUTES

Attribute Pos. Req. Default Description
page Yes Yes   Name of the Interchange page to process (as if the user visited it with the browser).
file Yes Yes   File to dump contents to.
scratch       Store contents in this scratch variable.
scan       Specifies the search string and reproduces a search results page.
auto_create_dir     0 Create directory path to the dump file?
expiry       See if file Modification time is newer than expiry deadline.
touch     0 If the file is expired, touch it?
umask       File creation umask.
interpolate     0 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

This tag processes the page (as if the user visited it with the browser), and writes contents to disk. This is usually called from jobs but of course, nothing enforces this.

The tag is able to reproduce both standard and search results pages.

This is similar to the output you could get from lynx -source or w3m -dump_source commands.

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

Example: Basic static page example

Create page named make-static.html with the following content:

[capture-page page=index file=static/index.html umask=022 auto_create_dir=1]

This would create the static/ directory in your catalog root, and a snapshot of index.html in it.


Create page named make-static2.html with the following content:

[loop list="Levels,Rulers,Squares"]
  [capture-page page="[loop-code]" file="static/cats/[loop-code].html"
    scan="fi=products/st=db/co=yes/sf=category/se=[loop-code]"
    auto_create_dir=1]
[/loop]

NOTES

See the umask glossary entry.

AVAILABILITY

capture_page is available in Interchange versions:

4.6.0-5.7.0 (git-head)

SOURCE

Interchange 5.7.0:

Source: code/UserTag/capture_page.tag
Lines: 86


# Copyright 2003-2008 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: capture_page.tag,v 1.12 2008-10-01 09:21:45 racke Exp $

UserTag capture_page Order   page file
UserTag capture_page addAttr
UserTag capture_page Version $Revision: 1.12 $
UserTag capture_page Routine <<EOR
sub {
my ($page, $file, $opt) = @_;

# check if we are using a file
if ($file) {
  # check if we are allowed to write the file
  unless (Vend::File::allowed_file($file, 1)) {
    Vend::File::log_file_violation($file, 'capture_page');
    return 0;
  }

  if ($opt->{expiry}) {
    my $stat = (stat($file))[9];

    if ($stat > $opt->{expiry}) {
      if ($opt->{touch}) {
        my $now = time();
        unless (utime ($now, $now, $file)) {
          ::logError ("Error on touching file $file: $!\n");
        }
      }
      return;
    }
  }
}

if ($opt->{scan}) {
  Vend::Page::do_scan($opt->{scan});
}

$::Scratch->{mv_no_count} = 1;

# save mapped output
my (@output, %outptr, %outfilter, %outextended, $multiout, $content, $retval);

@output = @Vend::Output;
%outptr = %Vend::OutPtr;
%outfilter = %Vend::OutFilter;
%outextended = %Vend::OutExtended;
$multiout = $Vend::MultiOutput;

# clear mapped output
@Vend::Output = %Vend::OutPtr = %Vend::OutFilter = %Vend::OutExtended = ();
$Vend::MultiOutput = 0;
  
Vend::Page::display_page($page, {return => 1});

for my $part (@Vend::Output) {
   Vend::Interpolate::substitute_image($part);
  $content .= $$part;
 }

# restore mapped output
@Vend::Output = @output;
%Vend::OutPtr = %outptr;
%Vend::OutFilter = %outfilter;
%Vend::OutExtended = %outextended;
$Vend::MultiOutput = $multiout;

if ($opt->{scratch}) {
  $::Scratch->{$opt->{scratch}} = $content;
  $retval = 1;
}

if ($file) {
   $retval = Vend::File::writefile (">$file", \$content,
         {auto_create_dir => $opt->{auto_create_dir},
         umask => $opt->{umask}});
}

return $retval;
}
EOR

AUTHORS

Stefan Hornburg (Racke), Interchange Development Group

SEE ALSO

DocBook! Interchange!