Esempio n. 1
0
 function displayAttachment($asSource = false)
 {
     global $xoopsModule, $xoopsModuleConfig;
     $post_attachment = '';
     $attachments = $this->getAttachment();
     if (is_array($attachments) && count($attachments) > 0) {
         $image_extensions = array("jpg", "jpeg", "gif", "png", "bmp");
         // need improve !!!
         $post_attachment .= '<br /><strong>' . _MD_ATTACHMENT . '</strong>:';
         $post_attachment .= '<br /><hr size="1" noshade="noshade" /><br />';
         foreach ($attachments as $key => $att) {
             $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.');
             $filetype = $file_extension;
             if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/images/filetypes/' . $filetype . '.gif')) {
                 $icon_filetype = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/images/filetypes/' . $filetype . '.gif';
             } else {
                 $icon_filetype = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/images/filetypes/unknown.gif';
             }
             $file_size = filesize(XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $att['name_saved']);
             $file_size = number_format($file_size / 1024, 2) . " KB";
             if (in_array(strtolower($file_extension), $image_extensions) && $xoopsModuleConfig['media_allowed']) {
                 $post_attachment .= '<br /><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong>&nbsp; ' . $att['name_display'] . '</strong> <small>(' . $file_size . ')</small>';
                 $post_attachment .= '<br />' . newbb_attachmentImage($att['name_saved'], $asSource);
                 $isDisplayed = true;
             } else {
                 $post_attachment .= '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/dl_attachment.php?attachid=' . $key . '&amp;post_id=' . $this->getVar('post_id') . '"> <img src="' . $icon_filetype . '" alt="' . $filetype . '" /> ' . $att['name_display'] . '</a> ' . _MD_FILESIZE . ': ' . $file_size . '; ' . _MD_HITS . ': ' . $att['num_download'];
             }
             $post_attachment .= '<br />';
         }
     }
     return $post_attachment;
 }
Esempio n. 2
0
 /** 
  * TODO: refactor
  */
 function displayAttachment($asSource = false)
 {
     global $xoopsModule, $xoopsModuleConfig;
     $post_attachment = '';
     $attachments = $this->getAttachment();
     if (is_array($attachments) && count($attachments) > 0) {
         $icon_handler = newbb_getIconHandler();
         $mime_path = $icon_handler->getPath("mime");
         include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar("dirname", "n") . '/include/functions.image.php';
         $image_extensions = array("jpg", "jpeg", "gif", "png", "bmp");
         // need improve !!!
         $post_attachment .= '<br /><strong>' . _MD_ATTACHMENT . '</strong>:';
         $post_attachment .= '<br /><hr size="1" noshade="noshade" /><br />';
         foreach ($attachments as $key => $att) {
             $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.');
             $filetype = $file_extension;
             if (file_exists(XOOPS_ROOT_PATH . '/' . $mime_path . '/' . $filetype . '.gif')) {
                 $icon_filetype = XOOPS_URL . '/' . $mime_path . '/' . $filetype . '.gif';
             } else {
                 $icon_filetype = XOOPS_URL . '/' . $mime_path . '/unknown.gif';
             }
             $file_size = @filesize(XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $att['name_saved']);
             $file_size = number_format($file_size / 1024, 2) . " KB";
             if (in_array(strtolower($file_extension), $image_extensions) && $xoopsModuleConfig['media_allowed']) {
                 $post_attachment .= '<br /><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong>&nbsp; ' . $att['name_display'] . '</strong> <small>(' . $file_size . ')</small>';
                 $post_attachment .= '<br />' . newbb_attachmentImage($att['name_saved']);
                 $isDisplayed = true;
             } else {
                 global $xoopsUser;
                 if ($xoopsUser && $xoopsUser->uid() > 0 && $xoopsUser->isactive() || empty($xoopsModuleConfig['show_only_user_attach'])) {
                     $post_attachment .= '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar("dirname", "n") . '/dl_attachment.php?attachid=' . $key . '&amp;post_id=' . $this->getVar('post_id') . '"> <img src="' . $icon_filetype . '" alt="' . $filetype . '" /> ' . $att['name_display'] . '</a> ' . _MD_FILESIZE . ': ' . $file_size . '; ' . _MD_HITS . ': ' . $att['num_download'];
                 } else {
                     $post_attachment .= _MD_NEWBB_SEENOTGUEST;
                 }
             }
             $post_attachment .= '<br />';
         }
     }
     return $post_attachment;
 }