add rich edit utils remove export class cuz it was moved to asset.pm
This commit is contained in:
parent
28b6653e2a
commit
eccf36ed27
2 changed files with 231 additions and 269 deletions
|
|
@ -1,269 +0,0 @@
|
|||
package WebGUI::Export;
|
||||
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2004 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::HTTP;
|
||||
use WebGUI::URL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Export
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This package provides methods to export WebGUI content.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Export;
|
||||
|
||||
# Generate an export of current page:
|
||||
$e = new WebGUI::Export();
|
||||
$html = $e->generate;
|
||||
|
||||
# Generate an export of pageId 238:
|
||||
$e = new WebGUI::Export();
|
||||
$e->set(pageId=>238);
|
||||
$html = $e->generate;
|
||||
|
||||
# Some more options
|
||||
$e = new WebGUI::Export(
|
||||
pageId => 1021,
|
||||
styleId => 1000,
|
||||
userId => 3,
|
||||
altSiteURL => "http://www.exportsite.nl/",
|
||||
extrasURL => "http://www.webguisite.com/extras"
|
||||
);
|
||||
$e->generate;
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this package:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 generate ( )
|
||||
|
||||
Executes the export and returns html content.
|
||||
|
||||
=head3 filename
|
||||
|
||||
Full path to a file.
|
||||
|
||||
=cut
|
||||
|
||||
sub generate {
|
||||
my $self = shift;
|
||||
my $fileName = shift;
|
||||
|
||||
# Save current session information because we need to restore current session after
|
||||
# the export has finished.
|
||||
my %oldSession = %session;
|
||||
|
||||
# Refresh session for userId, defaults to visitor
|
||||
WebGUI::Session::refreshUserInfo($self->get('userId') || 1,$session{dbh});
|
||||
|
||||
# Delete all form parameters
|
||||
delete $session{form};
|
||||
|
||||
# Admin bar
|
||||
$session{var}{adminOn} = $self->get('adminOn');
|
||||
|
||||
# Set the page to export.
|
||||
WebGUI::Session::refreshPageInfo($self->get('pageId'));
|
||||
|
||||
# Caching
|
||||
if($self->get('noCache')) {
|
||||
$session{page}{cacheTimeout} = 0;
|
||||
$session{page}{cacheTimeoutVisitor} = 0;
|
||||
}
|
||||
|
||||
# Uploads / Extras URL
|
||||
$session{config}{uploadsURL} = $self->get('uploadsURL') || $session{config}{uploadsURL};
|
||||
$session{config}{extrasURL} = $self->get('extrasURL') || $session{config}{extrasURL};
|
||||
|
||||
# Disable printing of HTTP Header if requested.
|
||||
if($self->get('noHttpHeader')) {
|
||||
WebGUI::HTTP::setNoHeader(1);
|
||||
}
|
||||
|
||||
# Set alternate Site URL
|
||||
if($self->get('altSiteURL')) {
|
||||
WebGUI::URL::setSiteURL($self->get('altSiteURL'));
|
||||
} elsif ($self->get('relativeUrls')) {
|
||||
WebGUI::URL::setSiteURL("./");
|
||||
my $url = $session{page}{urlizedTitle};
|
||||
while ($url =~ /\//g) {
|
||||
WebGUI::URL::setSiteURL(WebGUI::URL::getSiteURL()."../");
|
||||
}
|
||||
}
|
||||
# !!! At this point we make URLs absolute only if altSiteURL is not set.
|
||||
|
||||
# Set alternate Style
|
||||
$session{page}{styleId} = $self->get('styleId') || $session{page}{styleId};
|
||||
|
||||
# Generate the page
|
||||
my $content = WebGUI::page(undef, undef, 1, $session{page}{urlizedTitle});
|
||||
|
||||
if($self->get('stripHTML')) {
|
||||
$content = WebGUI::HTML::html2text($content);
|
||||
} elsif (not $session{url}{siteURL}) { # Implies absolute links
|
||||
$content = WebGUI::HTML::makeAbsolute($content);
|
||||
}
|
||||
|
||||
# Restore session
|
||||
%session = %oldSession;
|
||||
delete $session{page}{noHttpHeader};
|
||||
delete $session{url}{siteURL};
|
||||
return $content;
|
||||
|
||||
}
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( [ options ] )
|
||||
|
||||
Constructor.
|
||||
|
||||
Options can be set when a new Export object is constructed, or
|
||||
afterwards with the set method. None of the options is required.
|
||||
|
||||
=head3 pageId
|
||||
|
||||
Sets the page to be generated. Defaults to current page.
|
||||
|
||||
=head3 styleId
|
||||
|
||||
Use this to override the default styleId.
|
||||
Defaults to the page styleId.
|
||||
|
||||
=head3 userId
|
||||
|
||||
Runs the export as this user. Defaults to 1 (Visitor).
|
||||
|
||||
=head3 altSiteURL
|
||||
|
||||
Use this to override the absolute site URL. A valid value
|
||||
would be "http://www.site.com/". Setting this negates the effect
|
||||
of the relativeUrls option.
|
||||
|
||||
=head3 noCache
|
||||
|
||||
Is set to true by default. This will make sure
|
||||
that the exported page is generated and not fetched from cache.
|
||||
|
||||
=head3 noHttpHeader
|
||||
|
||||
Turns off the inclusion of a HTTP header. By default this option
|
||||
is set to true.
|
||||
|
||||
=head3 adminOn
|
||||
|
||||
Turns on / off the adminbar in the generated page. Is false by
|
||||
default.
|
||||
|
||||
=head3 stripHTML
|
||||
|
||||
Strips HTML from the document and outputs only text. Is disabled
|
||||
by default.
|
||||
|
||||
=head3 relativeUrls
|
||||
|
||||
If set, all navigation URL's will be constructed relative. By default
|
||||
all links will be made absolute. This option is negated if altSiteURL
|
||||
is set.
|
||||
|
||||
=head3 extrasURL
|
||||
|
||||
You can specify an alternate URL for the extras location. By default
|
||||
the extrasURL setting from the config file is used.
|
||||
|
||||
=head3 uploadsURL
|
||||
|
||||
You can specify an alternate URL for the uploads location. By default
|
||||
the uploadsURL setting from the config file is used.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
WebGUI::ErrorHandler::fatalError('WebGUI::Export->new() called with odd number of option parameters - should be of the form option => value') unless $#_ % 2;;
|
||||
my %var = @_;
|
||||
my $self = bless {}, $class;
|
||||
my %default = (
|
||||
uploadsURL => $session{config}{uploadsURL},
|
||||
extrasURL => $session{config}{extrasURL},
|
||||
pageId => $session{page}{pageId},
|
||||
styleId => undef,
|
||||
userId => 1,
|
||||
noCache => 1,
|
||||
noHttpHeader => 1,
|
||||
adminOn => 0,
|
||||
stripHTML => 0,
|
||||
altSiteURL => undef,
|
||||
relativeUrls => 0,
|
||||
);
|
||||
%var = ( %default, %var);
|
||||
$self->set(%var);
|
||||
return $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( key )
|
||||
|
||||
Gets the value for key from the class.
|
||||
|
||||
=head3 key
|
||||
|
||||
See documentation on the "new" constructor for an overview of all options.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
my $self = shift;
|
||||
my $key = shift;
|
||||
return $self->{"_".$key};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 set ( options )
|
||||
|
||||
Sets properties for this export to the object.
|
||||
|
||||
=head3 options
|
||||
|
||||
See documentation on the "new" constructor for an overview of all options.
|
||||
|
||||
=cut
|
||||
|
||||
sub set {
|
||||
my $self = shift;
|
||||
my %var = @_;
|
||||
foreach (keys %var) {
|
||||
$self->{"_".$_} = $var{$_}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
231
lib/WebGUI/Operation/RichEdit.pm
Normal file
231
lib/WebGUI/Operation/RichEdit.pm
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
package WebGUI::Operation::RichEdit;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2004 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Session;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
sub www_richEditPageTree {
|
||||
my $f = WebGUI::HTMLForm->new(-action=>"#");
|
||||
$f->text(
|
||||
-name=>"url",
|
||||
-label=>"URL",
|
||||
-extras=>'id="url"'
|
||||
);
|
||||
$f->yesNo(
|
||||
-name=>"newWindow",
|
||||
-label=>"Open in new window?"
|
||||
);
|
||||
$f->button(
|
||||
-value=>"Done",
|
||||
-extras=>'onclick="window.opener.blah()"'
|
||||
);
|
||||
my $output = $f->print.'<hr>';
|
||||
my $base = WebGUI::Asset->newByUrl || WebGUI::Asset->getRoot;
|
||||
my @crumb;
|
||||
my $ancestors = $base->getLineage(["self","ancestors"],{returnQuickReadObjects=>1});
|
||||
foreach my $ancestor (@{$ancestors}) {
|
||||
push(@crumb,'<a href="'.$ancestor->getUrl("op=richEditPageTree").'">'.$ancestor->get("menuTitle").'</a>');
|
||||
}
|
||||
$output .= '<p>'.join(" > ", @crumb)."</p>\n";
|
||||
my $children = $base->getLineage(["children"],{returnQuickReadObjects=>1});
|
||||
foreach my $child (@{$children}) {
|
||||
$output .= '<a href="'.$child->getUrl("op=richEditPageTree").'">(•)</a> <a href="#" onclick="document.getElementById(\'url\').value=\''.$child->getUrl.'\'">'.$child->get("menuTitle").'</a>'."<br />\n";
|
||||
}
|
||||
$session{page}{useEmptyStyle} = 1;
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _htmlAreaCreateTree {
|
||||
my ($output);
|
||||
my ($name, $description, $url, $image, $indent, $target, $delete) = @_;
|
||||
if($delete) {
|
||||
$delete = qq/<a href="javascript:deleteCollateral('$delete')" title="delete $name">/;
|
||||
$delete .= deleteIcon()."</a>";
|
||||
}
|
||||
$target = ' target="'.$target.'" ' if ($target);
|
||||
$output .= '<tr><td align="left" valign="bottom" width="100%">';
|
||||
$output .= ('<img src="'.$session{config}{extrasURL}.'/tinymce/images/indent.gif" width="17" heigth="17">') x$indent;
|
||||
$output .= '<img src="'.$session{config}{extrasURL}.'/tinymce/images/'.$image.'" align="bottom" alt="'.$name.'">';
|
||||
$output .= '<a title="'.$description.'" href="'.$url.'" '.$target.'><b>'.$name.'</b></a></td>';
|
||||
$output .= '<td class="delete" align="right" valign="bottom">'.$delete.'</td></tr>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_htmlArealistCollateral {
|
||||
my (@parents, $sth, $data, $indent);
|
||||
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
|
||||
return "<b>Only Content Managers are allowed to use WebGUI Collateral</b>" unless (WebGUI::Grouping::isInGroup(4));
|
||||
|
||||
my $output = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
|
||||
my $folderId = $session{form}{fid} || 0;
|
||||
my $parent = $folderId;
|
||||
# push parent folders in array so it can be reversed
|
||||
unshift(@parents, $parent);
|
||||
until($parent eq '0') {
|
||||
($parent) = WebGUI::SQL->quickArray("select parentId from collateralFolder where collateralFolderId=".quote($parent));
|
||||
unshift(@parents, $parent);
|
||||
}
|
||||
# Build tree for opened parent folders
|
||||
foreach $parent (@parents) {
|
||||
my ($name, $description) = WebGUI::SQL->quickArray("select name, description from
|
||||
collateralFolder where collateralFolderId=".quote($parent));
|
||||
my ($itemsInFolder) = WebGUI::SQL->quickArray("select count(*) from collateral where collateralFolderId = ".quote($parent));
|
||||
my ($foldersInFolder)=WebGUI::SQL->quickArray("select count(*) from collateralFolder where parentId=".quote($parent));
|
||||
my $delete = "fid=$parent" unless ($itemsInFolder + $foldersInFolder);
|
||||
$output .= _htmlAreaCreateTree($name, $description,
|
||||
WebGUI::URL::page('op=htmlArealistCollateral&fid='.$parent), "opened.gif",
|
||||
$indent++,"" ,$delete);
|
||||
}
|
||||
# Extend tree with closed folders in current folder
|
||||
$sth = WebGUI::SQL->read("select collateralFolderId, name, description from collateralFolder
|
||||
where parentId=".quote($folderId)." and collateralFolderId <> '0' order by name");
|
||||
while ($data = $sth->hashRef) {
|
||||
my ($itemsInFolder) = WebGUI::SQL->quickArray("select count(*) from collateral where
|
||||
collateralFolderId = ".quote($data->{collateralFolderId}));
|
||||
my $delete = 'fid='.$data->{collateralFolderId} unless $itemsInFolder;
|
||||
$output .= _htmlAreaCreateTree($data->{name}, $data->{description},
|
||||
WebGUI::URL::page('op=htmlArealistCollateral&fid='.$data->{collateralFolderId}),
|
||||
"closed.gif", $indent, "", $delete);
|
||||
}
|
||||
# Extend tree with images in current folder
|
||||
$sth = WebGUI::SQL->read("select collateralId, name, filename from collateral where collateralType = 'image' ".
|
||||
"and collateralFolderId = ".quote($folderId));
|
||||
while ($data = $sth->hashRef) {
|
||||
$data->{filename} =~ /\.([^\.]+)$/; # Get extension
|
||||
my $fileType = $1.'.gif';
|
||||
$output .= _htmlAreaCreateTree($data->{filename}, $data->{name},
|
||||
WebGUI::URL::page('op=htmlAreaviewCollateral&cid='.$data->{collateralId}),
|
||||
$fileType, $indent, "viewer", 'cid='.$data->{collateralId}.'&fid='.$folderId);
|
||||
}
|
||||
$output .= '</table>';
|
||||
$output .= '<script language="javascript">'."\n".'actionComplete("","'.$folderId.'","","");';
|
||||
$output .= "\n</script>\n";
|
||||
$sth->finish;
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_htmlAreaviewCollateral {
|
||||
my($output, $collateral, $file, $x, $y, $image, $error);
|
||||
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
|
||||
$output .= '<table align="center" border="0" cellspacing="0" cellpadding="2" width="100%" height="100%">';
|
||||
if($session{form}{cid} eq "" || ! WebGUI::Grouping::isInGroup(4)) {
|
||||
$output .= '<tr><td align="center" valign="middle" width="100%" height="100%">';
|
||||
$output .= '<p align="center"><br><img src="'.$session{config}{extrasURL}.'/tinymce/images/icon.gif"
|
||||
border="0"></p>';
|
||||
$output .= '<P align=center><STRONG>WebGUI Image Manager<BR>for TinyMCE</STRONG></P>';
|
||||
$output .= '</td></tr></table>';
|
||||
} else {
|
||||
my $c = WebGUI::Collateral->new($session{form}{cid});
|
||||
$collateral = $c->get;
|
||||
$file = WebGUI::Attachment->new($collateral->{filename},"images",$collateral->{collateralId});
|
||||
$output .= '<tr><td class="label" align="center" valign="middle" width="100%">';
|
||||
$output .= '<b>'.$file->getFilename.'</b><br>';
|
||||
# if ($hasImageMagick) {
|
||||
# $image = Image::Magick->new;
|
||||
# $error = $image->Read($file->getPath);
|
||||
# ($x, $y) = $image->Get('width','height');
|
||||
# $output .= $error ? "Error reading image: $error" : "<i>($x × $y)</i>";
|
||||
# }
|
||||
$output .= '</td></tr><tr><td align="center" valign="middle" width="100%" height="100%">';
|
||||
$output .= '<img src="'.$file->getThumbnail.'" border="0">';
|
||||
$output .= '</td></tr></table>';
|
||||
$output .= '<script language="javascript">';
|
||||
$output .= "\nvar src = '".$file->getURL."';\n";
|
||||
$output .= "if(src.length > 0) {
|
||||
var manager=window.parent;
|
||||
if(manager)
|
||||
manager.document.getElementById('txtFileName').value = src;
|
||||
}
|
||||
</script>\n";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_htmlAreaUpload {
|
||||
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
|
||||
return "<b>Only Content Managers are allowed to use WebGUI Collateral</b>" unless (WebGUI::Grouping::isInGroup(4));
|
||||
return www_htmlArealistCollateral() if ($session{form}{image} eq "");
|
||||
my($test, $file);
|
||||
$session{form}{fid} = $session{form}{collateralFolderId} = $session{form}{path};
|
||||
my $collateral = WebGUI::Collateral->new("new");
|
||||
$session{form}{thumbnailSize} ||= $session{setting}{thumbnailSize};
|
||||
$session{form}{cid} = $collateral->get("collateralId");
|
||||
$collateral->save("image", $session{form}{thumbnailSize});
|
||||
$session{form}{name} = "untitled" if ($session{form}{name} eq "");
|
||||
while (($test) = WebGUI::SQL->quickArray("select name from collateral
|
||||
where name=".quote($session{form}{name})." and collateralId<>".quote($collateral->get("collateralId")))) {
|
||||
if ($session{form}{name} =~ /(.*)(\d+$)/) {
|
||||
$session{form}{name} = $1.($2+1);
|
||||
} elsif ($test ne "") {
|
||||
$session{form}{name} .= "2";
|
||||
}
|
||||
}
|
||||
$collateral->set($session{form});
|
||||
$session{form}{collateralType} = "";
|
||||
return www_htmlArealistCollateral();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_htmlAreaDelete {
|
||||
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
|
||||
return "<b>Only Content Managers are allowed to use WebGUI Collateral</b>" unless (WebGUI::Grouping::isInGroup(4));
|
||||
if($session{form}{cid}) { # Delete Image
|
||||
my $collateral = WebGUI::Collateral->new($session{form}{cid});
|
||||
$collateral->delete;
|
||||
} elsif($session{form}{fid} and not($session{form}{cid})) {
|
||||
return WebGUI::Privilege::vitalComponent() unless ($session{form}{fid} > 999);
|
||||
my ($parent) = WebGUI::SQL->quickArray("select parentId from collateralFolder where collateralFolderId=".quote($session{form}{fid}));
|
||||
WebGUI::SQL->write("delete from collateralFolder where collateralFolderId=".quote($session{form}{fid}));
|
||||
$session{form}{fid}=$parent;
|
||||
}
|
||||
return www_htmlArealistCollateral();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_htmlAreaCreateFolder {
|
||||
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
|
||||
return "<b>Only Content Managers are allowed to use WebGUI Collateral</b>" unless (WebGUI::Grouping::isInGroup(4));
|
||||
$session{form}{fid} = WebGUI::Id::generate();
|
||||
WebGUI::Session::setScratch("collateralFolderId",$session{form}{fid});
|
||||
WebGUI::SQL->write("insert into collateralFolder (collateralFolderId) values (".quote($session{form}{fid}).")");
|
||||
my $folderId = $session{scratch}{collateralFolderId} || 0;
|
||||
$session{form}{name} = $session{form}{folder};
|
||||
$session{form}{name} = "untitled" if ($session{form}{name} eq "");
|
||||
while (my ($test) = WebGUI::SQL->quickArray("select name from collateralFolder
|
||||
where name=".quote($session{form}{name})." and collateralFolderId<>".quote($folderId))) {
|
||||
if ($session{form}{name} =~ /(.*)(\d+$)/) {
|
||||
$session{form}{name} = $1.($2+1);
|
||||
} elsif ($test ne "") {
|
||||
$session{form}{name} .= "2";
|
||||
}
|
||||
}
|
||||
WebGUI::SQL->write("update collateralFolder set parentId=".quote($session{form}{path}).", name=".quote($session{form}{name})
|
||||
.", description=".quote($session{form}{description})." where collateralFolderId=".quote($folderId));
|
||||
$session{form}{fid} = $session{form}{path};
|
||||
return www_htmlArealistCollateral();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue