Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View alfasado's full-sized avatar

Alfasado Inc. alfasado

View GitHub Profile
@alfasado
alfasado / mt-tools-template.pl
Created November 29, 2012 09:26
Template for MT::Tool::Foo
#!/usr/bin/perl
package MT::Tool::Foo;
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 );
sub usage { '--debug 1' }
@alfasado
alfasado / mt-rebuild-queue
Created February 1, 2013 00:27
Movable Type's Publish Queue
use MT;
my $mt = MT->new;
require MT::TheSchwartz::FuncMap;
require MT::TheSchwartz::Job;
require MT::FileInfo;
require MT::WeblogPublisher;
my $funcmap = MT::TheSchwartz::FuncMap->load( { funcname => 'MT::Worker::Publish' } );
return unless $funcmap;
my @jobs = MT::TheSchwartz::Job->load( { funcid => $funcmap->funcid, },
{ 'sort' => 'priority',
<mt:Asset id="1">
<mt:AssetThumbnailFile width="32" square="1" convert2base64="1" setvar="src">
<mt:Var name="src" get_content_length="1" setvar="image_size">
<mt:If name="image_size" lt="32768">
<img src="data:<mt:AssetMimeType>;base64,<mt:Var name="src">" width="32" height="32" alt="<mt:AssetLabel escape="html">" />
<mt:else>
<img src="<mt:AssetThumbnailURL>" width="32" height="32" alt="<mt:AssetLabel escape="html">" />
</mt:If>
</mt:Asset>
@alfasado
alfasado / PowerCMS config
Last active December 14, 2015 07:58
PowerCMS config for demonstration.
Trigger1:
params:
- __mode=view
- _type=entrygroup
- saved=1
template_id: 93
Trigger2:
params:
- __mode=view
- _type=campaigngroup
@alfasado
alfasado / zipsearch.html
Created March 21, 2013 03:34
Find the address from the zip code using PowerCMS's CustomObject.
<?php
global $app;
$q = $app->param( 'q' );
$q = $app->db()->escape( $q );
$q = preg_replace( '/[^0-9]/', '', $q );
if ( $q ) {
$terms = array( 'name' => $q,
'class' => 'postalcode' );
$extra = array( 'limit' => 1 );
$postalcode = $app->load( 'CustomObject', $terms, $extra );
<?php
define( 'DataAPICacheDir', '/tmp/api_cache' );
define( 'DataAPIUploadCacheDir', '/tmp/upload' );
define( 'DataAPICacheTtl', 1200 );
define( 'DataAPICacheWithAuth', TRUE );
define( 'DataAPIURL', 'http://localhost/mt/mt-data-api.cgi' );
define( 'SendHTTPHeaderMethod', '' );
$cache_ttl = DataAPICacheTtl;
$cache_with_auth = DataAPICacheWithAuth;
$cache_dir = DataAPICacheDir;
package MAUS::Callbacks;
use strict;
sub _data_api_pre_save_entry {
my ( $cb, $app, $obj, $original ) = @_;
my $entry = $app->param( 'entry' );
$entry = MT::DataAPI::Format::JSON::unserialize( $entry );
# if ( $entry->{ 'convert_breaks' } ) {
# $obj->convert_breaks( lc( $entry->{ 'convert_breaks' } ) );
# }
id: MAUS
name: MAUS
key: maus
description: <__trans phrase="Set text format to Markdown(Post by MAUS).">
version: 0.1
author_name: Alfasado Inc.
author_link: http://alfasado.net/
l10n_class: MAUS::L10N
callbacks:
data_api_pre_save.entry: $maus::MAUS::Callbacks::_data_api_pre_save_entry
package MAUS::Callbacks;
use strict;
sub _data_api_pre_save_entry {
my ( $cb, $app, $obj, $original ) = @_;
my $entry = $app->param( 'entry' );
$entry = MT::DataAPI::Format::JSON::unserialize( $entry );
if ( $entry->{ 'convert_breaks' } ) {
$obj->convert_breaks( lc( $entry->{ 'convert_breaks' } ) );
}
name: ImportCheck
id: ImportCheck
version: 0.1
config_settings:
EntryPathCustomFieldBasename:
default: orig_entry_path
PagePathCustomFieldBasename:
default: orig_page_path
callbacks:
cms_post_import.entry: >