CatalystX-CMS

 view release on metacpan or  search on metacpan

lib/CatalystX/CMS.pm  view on Meta::CPAN

    unless ( -s $cmspage ) {
        croak( $cmspage->file . " does not exist" );
    }

    # lock the file immediately so no one else can edit it.
    # only the current user can unlock it, either by saving
    # changes or by explicitly calling the cancel url.

    # could be a redirect from create() so check that owner == $user
    my $user = $self->get_user($c);
    if ( $cmspage->locked ) {

        # how old is the lock?
        my $lock_period = $c->config->{cms}->{lock_period} || 3600;
        if ( ( $cmspage->lock_time + $lock_period ) < time() ) {
            $c->log->debug("lock expired on $cmspage");
            $cmspage->lock($user);
        }
        elsif ( $cmspage->lock_owner ne $user ) {
            croak( "$cmspage is already locked by " . $cmspage->lock_owner );
        }
        else {

            # extend the lock every time we hit this url
            if ( $cmspage->unlock && $cmspage->lock($user) ) {
                $c->log->debug("$cmspage lock re-acquired by $user");
            }
            else {
                croak("failed to re-acquire $cmspage lock for $user");
            }

lib/CatalystX/CMS.pm  view on Meta::CPAN

sub do_action {
    my ( $self, $c, $controller, $cmspage ) = @_;

    my $text = $c->req->params->{text};
    if ( !defined $text ) {
        croak('text param required');
    }
    my $action = $c->stash->{cms_mode} || 'save';
    my $user = $self->get_user($c);

    # is this file locked by this user?
    if ( !$cmspage->locked ) {
        croak( $cmspage->url . " is not locked for editing." );
    }

    if ( $cmspage->lock_owner ne $user ) {
        croak( $cmspage->url . " is not locked by $user." );
    }

    # YUI editor adds HTML <br> to represent \n
    # so filter those and any others.
    my $filter += $self->_filter_text( \$text );

    $self->_get_attrs( $c, $cmspage );
    $cmspage->content($text);

    $c->log->debug("Action = $action") if $c->debug;

lib/CatalystX/CMS.pm  view on Meta::CPAN


Called by DELETE(). Removes lock on I<cmspage> and 
deletes the file from the local workspace B<and from the svn
repository>. See also cancel().

=cut

sub delete {
    my ( $self, $c, $controller, $cmspage ) = @_;

    if ( $cmspage->locked ) {
        $cmspage->unlock or croak("can't unlock $cmspage");
    }

    my $user = $self->get_user($c);
    my $stat = $cmspage->status;
    if ($stat) {

        # if the page has local mods, then remove working copy,
        # svn update, and then svn delete

lib/CatalystX/CMS/File.pm  view on Meta::CPAN

                        );
 eval { $file->save  } or die $file->errstr;
 print "$file was saved\n";
                        
=head1 DESCRIPTION

CatalystX::CMS::File is the object model for the Template Toolkit files that
make up the content system of your application. 
Each object represents a C<.tt>
file on the filesystem in a Subversion working directory.
An object can be read, written, locked and unlocked on the filesystem.
As a subclass of SVN::Class::File, the object can be interrogated 
for its history, added, deleted, committed or updated.

=head2 new( I<path> )

=head2 new( path => I<path> [, %param ] )

Create a new object.

Either form of new() may be used, but I<path> is always

lib/CatalystX/CMS/File.pm  view on Meta::CPAN

    return $self;
}

=head2 write( [I<ignore_lock>] )

Writes attrs() and content() to file location in TT-compatible format.

Will croak on any error.

If the I<ignore_lock> flag is true, write() will ignore any true
value of locked(). Otherwise, will croak() if locked() is true.

Returns the size of the resulting file.

=cut

sub write {
    my $self = shift;
    my $force = shift || 0;

    if ( $self->locked && !$force ) {
        croak "write failed. $self is locked";
    }

    my $fh = $self->openw();

    # make sure we have at least one newline at end of file.
    my $content = $self->content || '';
    chomp $content;
    $content .= "\n";
    $self->_unescape( \$content );

lib/CatalystX/CMS/File.pm  view on Meta::CPAN


=cut

sub create {
    my $self = shift;
    my $user = shift or croak "user required";

    # create any required parent directories
    $self->dir->mkpath();

    if ( $self->locked or -s $self ) {
        croak "cannot create $self : locked or already exists";
    }

    $self->lock($user);
    $self->attrs->{owner} = $user;
    $self->content('[ this is a new page ]');
    return $self->write(1);
}

=head2 update

lib/CatalystX/CMS/tt/cms/svn/links.tt  view on Meta::CPAN

 <div class="bd">
  <form method="post" action="[% cmspage_url %]?cxcms=rename">
   <input type="text" size="50" maxsize="255" name="cxcms-url" value="" />
  </form>
 </div>
</div>

</div><!-- end top-panel -->

<div id="right-panel">
[% IF cmspage.locked %]
 [% 
   SET datearr  = [];
   USE datestr  = date(format = '%Y,%m,%d,%H,%M,%S');
   ltime        = cmspage.lock_time + (c.config.cms.lock_period || 3600);
   datearr      = datestr.format( ltime ).split(',');
   datearr.1    = datearr.1 - 1;  # fix month
 %]
<script type="text/javascript">
 <!-- //start
 CMS.LOCK_EXPIRES = new Date([% datearr.join(',') %]);
 //-->
</script>

 <div id="countbox_cont">
 Page lock remaining: <span id="countbox"></span>
 </div>
[% END # cmspage.locked %]

 <div id="cms_attrs" class="boxed padded">
  <span id="cms_attrs_template" style="display:none">
   <input class="label" type="text" name="new_attr_name" value="meta name" />
   <input               type="text" name="new_attr_val"  value="meta value" />
   <br />
  </span>
 [% FOREACH m = cmspage.attrs.keys.sort %]
   <label>[% m | html %]</label>
   <input type="text" name="[% m | html %]" value="[% cmspage.attrs.$m %]" />



( run in 1.293 second using v1.01-cache-2.11-cpan-26ccb49234f )