Skip to content

Instantly share code, notes, and snippets.

Avatar

Alfasado Inc. alfasado

View GitHub Profile
@alfasado
alfasado / mt-tools-template.pl
Created Nov 29, 2012
Template for MT::Tool::Foo
View mt-tools-template.pl
#!/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 Feb 1, 2013
Movable Type's Publish Queue
View mt-rebuild-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',
View data URI scheme in MTML
<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 Dec 14, 2015
PowerCMS config for demonstration.
View PowerCMS config
Trigger1:
params:
- __mode=view
- _type=entrygroup
- saved=1
template_id: 93
Trigger2:
params:
- __mode=view
- _type=campaigngroup
@alfasado
alfasado / zipsearch.html
Created Mar 21, 2013
Find the address from the zip code using PowerCMS's CustomObject.
View zipsearch.html
<?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 );
View mt-data-api-proxy.php
<?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;
View Callbacks.pm
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' } ) );
# }
View config.yaml
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
View Callbacks.pm(Old)
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' } ) );
}
View powercms-plugin-import-check
name: ImportCheck
id: ImportCheck
version: 0.1
config_settings:
EntryPathCustomFieldBasename:
default: orig_entry_path
PagePathCustomFieldBasename:
default: orig_page_path
callbacks:
cms_post_import.entry: >