画像をアップロードしたときに、右寄せか左寄せかを自由に選択できるようにする方法を、juanlogさんが紹介していたのでやってみた。これはすごい!
1:「upload_complete/tmpl」を編集
まず、tmpl/cms/upload_complete.tmplをterapad(文字コードを指定して開いたり保存できたりして便利!)などのテキストエディターで開き、以下を修正。
オリジナル
<td align="right" valign="top" colspan="3"><font class="instructional"><input type="checkbox" name="constrain" value="1" checked> <MT_TRANS phrase="Constrain proportions"></td>
</tr>
</table>
修正後
<td align="right" valign="top" colspan="3"><font class="instructional"><input type="checkbox" name="constrain" value="1" checked> <MT_TRANS phrase="Constrain proportions"></td>
</tr>
<tr>
<td>Image floating:</td>
<td ><select name="ifloat" class="menu" >
<option value="left" selected>left
<option value="right" >right
<option value="none">none
</select></td>
</tr>
</table>
さらに以下を修正。
修正前
<input class="button-big" type="button" onClick="doClick(this.form, 'popup=1&width=<TMPL_VAR NAME=WIDTH>&height=<TMPL_VAR NAME=HEIGHT>&image_type=<TMPL_VAR NAME=IMAGE_TYPE>')" value="<MT_TRANS phrase="Popup Image">">
<input class="button-big" type="button" onClick="doClick(this.form, 'nclude=1&width=<TMPL_VAR NAME=WIDTH>&height=<TMPL_VAR NAME=HEIGHT>&image_type=<TMPL_VAR NAME=IMAGE_TYPE>')" value="<MT_TRANS phrase="Embedded Image">">
修正後
<input class="button-big" type="button" onClick="doClick(this.form, 'imgfloat='+this.form.ifloat.value+'&popup=1&width=<TMPL_VAR NAME=WIDTH>&height=<TMPL_VAR NAME=HEIGHT>&image_type=<TMPL_VAR NAME=IMAGE_TYPE>')" value="<MT_TRANS phrase="Popup Image">">
<input class="button-big" type="button" onClick="doClick(this.form, 'imgfloat='+this.form.ifloat.value+'&include=1&width=<TMPL_VAR NAME=WIDTH>&height=<TMPL_VAR NAME=HEIGHT>&image_type=<TMPL_VAR NAME=IMAGE_TYPE>')" value="<MT_TRANS phrase="Embedded Image">">
2:「CMS.pm」を修正
次に、lib/mt/app/CMS.pmを開き、以下を修正。
修正前
if ($q->param('popup')) {
require MT::Template;
if (my $tmpl = MT::Template->load({ blog_id => $blog_id,
type => 'popup_image' })) {
(my $base = $q->param('fname')) =~ s!\.[^.]*$!!;
if ($base =~ m!\.\.|\0|\|!) {
return $app->error($app->translate(
"Invalid basename '[_1]'", $base));
}
修正後
my $imgclass;
if ($q->param('imgfloat') eq 'left') {
$imgclass = " class='l' ";
}elsif ($q->param('imgfloat') eq 'right') {
$imgclass = " class='r' ";
}else {
$imgclass = '';
}
if ($q->param('popup')) {
require MT::Template;
if (my $tmpl = MT::Template->load({ blog_id => $blog_id,
type => 'popup_image' })) {
(my $base = $q->param('fname')) =~ s!\.[^.]*$!!;
if ($base =~ m!\.\.|\0|\|!) {
return $app->error($app->translate(
"Invalid basename '[_1]'", $base));
}
さらに以下を修正。
修正前
my $link = $thumb ? qq(<img $imgclass src="$thumb" width="$thumb_width" height="$thumb_height" border="0" />) : "View image";
return <<HTML;
<a href="$url" onclick="window.open('$url','popup','width=$width,height=$height,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">$link</a>
HTML
} elsif ($q->param('include')) {
(my $fname = $url) =~ s!^.*/!!;
if ($thumb) {
return <<HTML;
<a href="$url"><img $imgclass alt="$fname" src="$thumb" width="$thumb_width" height="$thumb_height" border="0" /></a>
HTML
} else {
return <<HTML;
<img alt="$fname" $imgclass src="$url" width="$width" height="$height" border="0" />
修正後
my $link = $thumb ? qq(<img $imgclass src="$thumb" width="$thumb_width" height="$thumb_height" border="0" />) : "View image";
return <<HTML;
<a href="$url" onclick="window.open('$url','popup','width=$width,height=$height,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">$link</a>
HTML
} elsif ($q->param('include')) {
(my $fname = $url) =~ s!^.*/!!;
if ($thumb) {
return <<HTML;
<a href="$url"><img $imgclass alt="$fname" src="$thumb" width="$thumb_width" height="$thumb_height" border="0" /></a>
HTML
} else {
return <<HTML;
<img alt="$fname" $imgclass src="$url" width="$width" height="$height" border="0" />
3:「styles-site.css」を修正
最後にスタイルシートに以下を加える。
img.r {
float: right;
border: none;
margin-right:4px;
margin-top:4px;
vertical-align:top;
}
img.l {
float: left;
border: none;
margin-right:4px;
margin-top:4px;
vertical-align:top;
}
あとはスタイルシートでcontentなど関連するところでpositionがabsoluteになっていたらそれを解除しないとfloteが有効にならないので注意!

