Joomler!.net - Decided on Joomla!

デル株式会社

Wiki or Wordpress? No it is JContentPlus.

Home » Blog » アップロードファイルとイメージ : Fireboard Hack
Mar
19
2008

アップロードファイルとイメージ : Fireboard Hack

EMailPrintPDF
0 votes
Written by:Joomler! 4217 hits

Fireboardのファイルとイメージのアップロードで以前から不満に思っていたのですが、アップロードに失敗などすると二度とアップロードできなくなってしまわないですか?これは、データベースに登録されてしまうとアップロード済みになってしまい、ファイルの存在の有無にかかわらずアップロードされていると判断しているからのようです。

以下のようにアップロード済みでファイルが存在するならタグを表示するようにしました。

fireboard_hack_upload.jpg

Root/components/com_fireboard/template/default/post.php

foreach ($attachments as $att)
{
 if (preg_match("&/fbfiles/files/&si", $att->filelocation)) {
  $no_file_upload = "1";
 }
 
 if (preg_match("&/fbfiles/images/&si", $att->filelocation)) {
  $no_image_upload = "1";
 }
}

$upload_files = array();
$upload_images = array();
foreach ($attachments as $att)
{
 if (preg_match("&/fbfiles/files/&si", $att->filelocation) && file_exists($att->filelocation)) {
  $no_file_upload = "1";
  $upload_files[] = '[file]'. str_replace($mosConfig_absolute_path, $mosConfig_live_site, $att->filelocation). '[/file]';
 }
 
 if (preg_match("&/fbfiles/images/&si", $att->filelocation) && file_exists($att->filelocation)) {
  $no_image_upload = "1";
  $upload_images[] = '[img]'. str_replace($mosConfig_absolute_path, $mosConfig_live_site, $att->filelocation). '[/img]';
 }
}

に変更。そしてこのとき追加した$upload_filesと$upload_imagesを次のファイルで使います。

Root/components/com_fireboard/template/default/fb_write.html.php

if (($fbConfig['allowImageUpload'] || ($fbConfig['allowImageRegUpload'] && $my->id != 0) || $is_moderator) && ($no_upload == "0" || $no_image_upload == "0"))
{
?>

    <tr class = "<?php echo $boardclass; ?>sectiontableentry1">
        <td class = "fb_leftcolumn">
            <strong><?php echo _IMAGE_SELECT_FILE; ?></strong>
        </td>

        <td>
            <input type = 'file' class = 'button' name = 'attachimage' onmouseover = "helpline('iu')"/>

            <input type = "button" class = "button" name = "addImagePH" value = "<?php echo _POST_ATTACH_IMAGE;?>" style = "cursor:hand; width: 40px" onclick = "javascript:emo(' [img] ');" onmouseover = "helpline('ip')"/>
        </td>
    </tr>

<?php
}
?>

<?php
if (($fbConfig['allowFileUpload'] || ($fbConfig['allowFileRegUpload'] && $my->id != 0) || $is_moderator) && ($no_upload == "0" || $no_file_upload == "0"))
{
?>

    <tr class = "<?php echo $boardclass; ?>sectiontableentry2">
        <td class = "fb_leftcolumn">
            <strong><?php echo _FILE_SELECT_FILE; ?></strong>
        </td>

        <td>
            <input type = 'file' class = 'button' name = 'attachfile' onmouseover = "helpline('fu')" style = "cursor:hand"/>

            <input type = "button" class = "button" name = "addFilePH" value = "<?php echo _POST_ATTACH_FILE;?>" style = "cursor:hand; width: 40px" onclick = "javascript:emo(' [file] ');" onmouseover = "helpline('fp')"/>
        </td>
    </tr>

<?php
}

if (($fbConfig['allowImageUpload'] || ($fbConfig['allowImageRegUpload'] && $my->id != 0) || $is_moderator) && ($no_upload == "0" || $no_image_upload == "0"))
{
?>

    <tr class = "<?php echo $boardclass; ?>sectiontableentry1">
        <td class = "fb_leftcolumn">
            <strong><?php echo _IMAGE_SELECT_FILE; ?></strong>
        </td>

        <td>
            <input type = 'file' class = 'button' name = 'attachimage' onmouseover = "helpline('iu')"/>

            <input type = "button" class = "button" name = "addImagePH" value = "<?php echo _POST_ATTACH_IMAGE;?>" style = "cursor:hand; width: 40px" onclick = "javascript:emo(' [img] ');" onmouseover = "helpline('ip')"/>
        </td>
    </tr>

<?php
}
if (($fbConfig['allowImageUpload'] || ($fbConfig['allowImageRegUpload'] && $my->id != 0) || $is_moderator) && count($upload_images) && $no_image_upload == "1")
{
?>

    <tr class = "<?php echo $boardclass; ?>sectiontableentry1">
        <td class = "fb_leftcolumn">
            <strong>アップロード済みイメージ</strong>
        </td>

        <td>
         <?php echo implode('<br />', $upload_images); ?>
        </td>
    </tr>

<?php
}
if (($fbConfig['allowFileUpload'] || ($fbConfig['allowFileRegUpload'] && $my->id != 0) || $is_moderator) && ($no_upload == "0" || $no_file_upload == "0"))
{
?>

    <tr class = "<?php echo $boardclass; ?>sectiontableentry2">
        <td class = "fb_leftcolumn">
            <strong><?php echo _FILE_SELECT_FILE; ?></strong>
        </td>

        <td>
            <input type = 'file' class = 'button' name = 'attachfile' onmouseover = "helpline('fu')" style = "cursor:hand"/>

            <input type = "button" class = "button" name = "addFilePH" value = "<?php echo _POST_ATTACH_FILE;?>" style = "cursor:hand; width: 40px" onclick = "javascript:emo(' [file] ');" onmouseover = "helpline('fp')"/>
        </td>
    </tr>

<?php
}
if (($fbConfig['allowFileUpload'] || ($fbConfig['allowFileRegUpload'] && $my->id != 0) || $is_moderator) && count($upload_files) && $no_file_upload == "1")
{
?>

    <tr class = "<?php echo $boardclass; ?>sectiontableentry2">
        <td class = "fb_leftcolumn">
            <strong>アップロード済みファイル</strong>
        </td>

        <td>
        <?php echo implode('<br />', $upload_files); ?>
        </td>
    </tr>

<?php
}

に変更。これでアップロード済みのファイルがあって且つファイルが存在していれば、アップロードフォームに代わってコピーして使えるタグ(自分で選択してコピーしないと駄目ですけど)が表示されます。
※メッセージなどは、好みで変更されたら良いと思うし、そこまでしなくてもと思われるなら、最初の変更分で$upload_files、$upload_imagesを定義しなければfb_write.html.phpも変更しなくてOKですね。


と、こうやって変更してみるとデータベースに登録時、ファイルの存在チェックをしていないことに気がつきますね。どんどんアップデートされるでしょうから、様子を見ながらですね。

ちなみにプロフィール部分のリンクを直そうと思っていたのですが、マルチアップロードについて書かれた以下の記事を見て思いつきました。マルチアップロードできるようにするHackが書かれています。

Upload Image or File Error

TagsError
 

ADD A COMMENT

Subject*
:
Color Swatch




Email Link Page Code Text Align Center Text Align Justify Text Align Left Text Align Right Text Bold Text Quote Text Italic Text List Bullets Text List Numbers Text Strikethrough Text Underline World Link
Sun Unhappy Smile Evilgrin Wink Tongue Lightning Surprised Grin Rain Clouds Cloudy Snow Waii
Name*
:
EMail*
:
Website
:

JContentPlus for Joomla!1.5 powered by Joomler!.net

デル株式会社

Related Items

The Joomla!(R) name is used under a limited license from Open Source Matters in the United States and other countries.
joomler.net is not affiliated with or endorsed by Open Source Matters or the Joomla! Project.