Skip to content

Instantly share code, notes, and snippets.

@junnama
junnama / revert-to-the-previous
Created Jan 22, 2016
Revert to the previous templates.
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 );
@junnama
junnama / config.yaml
Created Jan 21, 2016
Remove MTIgnore tag and HTML comments.
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;
@junnama
junnama / Proxy.pm
Last active Jan 18, 2016
MT::Meta::Proxy - MySQL bulk inserts
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' ) );
@junnama
junnama / config.yaml
Created Jan 12, 2016
Not overwrite Main Index by Page.
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;
@junnama
junnama / config.yaml
Created Dec 25, 2015
Add entry's title for edit entry screen.
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;
@junnama
junnama / gist:11106932
Last active Aug 29, 2015
EntriesFromRSS/php/config.php
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',
),