Instantly share code, notes, and snippets.

View revert-to-the-previous
#!/usr/bin/perl
package MT::Tool::RevertToThePrevious;
use strict;
use warnings;
use File::Spec;
use FindBin;
use lib map File::Spec->catdir( $FindBin::Bin, File::Spec->updir, $_ ),
qw/lib extlib/;
use base qw( MT::Tool );
View config.yaml
tags:
modifier:
remove_ignore: >
sub {
my ( $text, $arg ) = @_;
$text =~ s/<mt:{0,1}ignore>.*?<\/mt:{0,1}ignore>//gsi;
if ( $arg ne '1' ) {
my $comment = quotemeta( '<!--' );
my $comment_end = quotemeta( '-->' );
$text =~ s/$comment.*?$comment_end//sg;
View Proxy.pm
sub save {
my $proxy = shift;
# perl funkiness ... keys %{ $proxy->{__objects} } will automatically clobber
# empty hash reference on that key!
return unless $proxy->{__objects};
my @cols = qw( type vchar vchar_idx vdatetime
vdatetime_idx vinteger vinteger_idx vfloat
vfloat_idx vblob vclob );
my $od = lc( MT->config( 'ObjectDriver' ) );
View config.yaml
callbacks:
cms_save_filter.page: >
sub {
my ( $cb, $app ) = @_;
if ( ( $app->param( 'category_ids' ) eq '-1' ) &&
( $app->param( 'basename' ) eq 'index' ) ) {
return $cb->error( $app->translate( 'File [_1] exists; could not overwrite.',
$app->translate( 'Main Index' ) ) );
}
1;
View config.yaml
callbacks:
MT::App::CMS::template_param.edit_entry: >
sub {
my ( $cb, $app, $param, $tmpl ) = @_;
if ( $param->{ id } ) {
my $title_tags = $tmpl->getElementsByName( 'page_title' );
for my $tag ( @$title_tags ) {
my $value = $tag->getAttribute( 'value' );
my $title = $param->{ title };
$title = MT::Util::encode_html( $title ) if $title;
View gist:11106932
<?php
require_once( 'MTUtil.php' );
class EntriesFromRSS extends MTPlugin {
var $registry = array(
'config_settings' => array(
'RewriteArchiverRewriteTo' => array( 'default' => '/archiver.html' ),
),
'callbacks' => array(
'post_init' => 'rewrite_archiver',
),