Example #1
0
 protected function generate()
 {
     require_once KPATH_SITE . '/lib/kunena.link.class.php';
     if (!isset($this->_shorttype)) {
         $this->_shorttype = $this->isImage($this->filetype) ? 'image' : $this->filetype;
         $this->_shortname = KunenaForumMessageAttachmentHelper::shortenFileName($this->filename);
         $config = KunenaFactory::getConfig();
         $this->_imagelink = null;
         $template = KunenaFactory::getTemplate();
         switch (strtolower($this->_shorttype)) {
             case 'image':
                 // Check for thumbnail and if available, use for display
                 if (file_exists(JPATH_ROOT . '/' . $this->folder . '/thumb/' . $this->filename)) {
                     $thumb = $this->folder . '/thumb/' . $this->filename;
                     $imgsize = '';
                 } else {
                     $thumb = $this->folder . '/' . $this->filename;
                     $imgsize = 'width="' . $config->thumbwidth . 'px" height="' . $config->thumbheight . 'px"';
                 }
                 $img = '<img title="' . $this->escape($this->filename) . '" ' . $imgsize . ' src="' . JURI::ROOT() . $thumb . '" alt="' . $this->escape($this->filename) . '" />';
                 $this->_thumblink = CKunenaLink::GetAttachmentLink($this->escape($this->folder), $this->escape($this->filename), $img, $this->escape($this->filename), $config->lightbox ? 'lightbox[thumb' . intval($this->mesid) . ']' : '');
                 $img = '<img title="' . $this->escape($this->filename) . '" src="' . JURI::ROOT() . $this->escape($this->folder) . '/' . $this->escape($this->filename) . '" alt="' . $this->escape($this->filename) . '" />';
                 $this->_imagelink = CKunenaLink::GetAttachmentLink($this->escape($this->folder), $this->escape($this->filename), $img, $this->escape($this->filename), $config->lightbox ? 'lightbox[imagelink' . intval($this->mesid) . ']' : '');
                 $this->_textLink = CKunenaLink::GetAttachmentLink($this->escape($this->folder), $this->escape($this->filename), $this->escape($this->_shortname), $this->escape($this->filename), $config->lightbox ? 'lightbox[simple' . $this->mesid . ']' . ' nofollow' : ' nofollow') . ' (' . number_format(intval($this->size) / 1024, 0, '', ',') . 'KB)';
                 break;
             default:
                 // Filetype without thumbnail or icon support - use default file icon
                 $img = '<img src="' . JURI::root() . 'media/kunena/images/attach_generic.png" alt="' . JText::_('COM_KUNENA_ATTACH') . '" />';
                 $this->_thumblink = CKunenaLink::GetAttachmentLink($this->escape($this->folder), $this->escape($this->filename), $img, $this->escape($this->filename), 'nofollow');
                 $this->_textLink = CKunenaLink::GetAttachmentLink($this->escape($this->folder), $this->escape($this->filename), $this->escape($this->_shortname), $this->escape($this->filename), 'nofollow') . ' (' . number_format(intval($this->size) / 1024, 0, '', ',') . 'KB)';
         }
         $this->_disabled = false;
         if (!KunenaUserHelper::getMyself()->exists()) {
             if ($this->_shorttype == 'image' && !$config->showimgforguest) {
                 $this->_disabled = true;
                 $this->_textLink = JText::_('COM_KUNENA_SHOWIMGFORGUEST_HIDEIMG');
             }
             if ($this->_shorttype != 'image' && !$config->showfileforguest) {
                 $this->_disabled = true;
                 $this->_textLink = JText::_('COM_KUNENA_SHOWIMGFORGUEST_HIDEFILE');
             }
             if ($this->_disabled) {
                 $this->_thumblink = '<img src="' . JURI::root() . 'media/kunena/images/attach_generic.png" alt="' . JText::_('COM_KUNENA_ATTACH') . '" />';
                 $this->_imagelink = null;
                 $this->size = 0;
             }
         }
     }
 }
 function _get($attachments)
 {
     $ret = array();
     foreach ($attachments as $attachment) {
         // combine all images into one type
         $attachment->shorttype = $this->isImage($attachment->filetype) ? 'image' : $attachment->filetype;
         $attachment->shortname = CKunenaTools::shortenFileName($attachment->filename);
         switch (strtolower($attachment->shorttype)) {
             case 'image':
                 // Check for thumbnail and if available, use for display
                 if (file_exists(JPATH_ROOT . '/' . $attachment->folder . '/thumb/' . $attachment->filename)) {
                     $thumb = $attachment->folder . '/thumb/' . $attachment->filename;
                     $imgsize = '';
                 } else {
                     $thumb = $attachment->folder . '/' . $attachment->filename;
                     $imgsize = 'width="' . $this->_config->thumbwidth . 'px" height="' . $this->_config->thumbheight . 'px"';
                 }
                 $img = '<img title="' . $this->escape($attachment->filename) . '" ' . $imgsize . ' src="' . JURI::ROOT() . $thumb . '" alt="' . $this->escape($attachment->filename) . '" />';
                 $attachment->thumblink = CKunenaLink::GetAttachmentLink($this->escape($attachment->folder), $this->escape($attachment->filename), $img, $this->escape($attachment->filename), $this->_config->lightbox ? 'lightbox[thumb' . intval($attachment->mesid) . ']' : '');
                 $img = '<img title="' . $this->escape($attachment->filename) . '" src="' . JURI::ROOT() . $this->escape($attachment->folder) . '/' . $this->escape($attachment->filename) . '" alt="' . $this->escape($attachment->filename) . '" />';
                 $attachment->imagelink = CKunenaLink::GetAttachmentLink($this->escape($attachment->folder), $this->escape($attachment->filename), $img, $this->escape($attachment->filename), $this->_config->lightbox ? 'lightbox[imagelink' . intval($attachment->mesid) . ']' : '');
                 $attachment->textLink = CKunenaLink::GetAttachmentLink($this->escape($attachment->folder), $this->escape($attachment->filename), $this->escape($attachment->shortname), $this->escape($attachment->filename), $this->_config->lightbox ? 'lightbox[simple' . $attachment->mesid . ']' . ' nofollow' : ' nofollow') . ' (' . number_format(intval($attachment->size) / 1024, 0, '', ',') . 'KB)';
                 break;
             default:
                 // Filetype without thumbnail or icon support - use default file icon
                 $img = '<img src="' . KUNENA_URLICONSPATH . 'attach_generic.png" alt="' . JText::_('COM_KUNENA_ATTACH') . '" />';
                 $attachment->thumblink = CKunenaLink::GetAttachmentLink($this->escape($attachment->folder), $this->escape($attachment->filename), $img, $this->escape($attachment->filename), 'nofollow');
                 $attachment->textLink = CKunenaLink::GetAttachmentLink($this->escape($attachment->folder), $this->escape($attachment->filename), $this->escape($attachment->shortname), $this->escape($attachment->filename), 'nofollow') . ' (' . number_format(intval($attachment->size) / 1024, 0, '', ',') . 'KB)';
         }
         $attachment->disabled = false;
         if (!$this->_my->id) {
             if ($attachment->shorttype == 'image' && !$this->_config->showimgforguest) {
                 $attachment->disabled = true;
                 $attachment->textLink = JText::_('COM_KUNENA_SHOWIMGFORGUEST_HIDEIMG');
             }
             if ($attachment->shorttype != 'image' && !$this->_config->showfileforguest) {
                 $attachment->disabled = true;
                 $attachment->textLink = JText::_('COM_KUNENA_SHOWIMGFORGUEST_HIDEFILE');
             }
             if ($attachment->disabled) {
                 $attachment->thumblink = '<img src="' . KUNENA_URLICONSPATH . 'attach_generic.png" alt="' . JText::_('COM_KUNENA_ATTACH') . '" />';
                 unset($attachment->imagelink);
                 $attachment->size = 0;
             }
         }
         $this->_instances[$attachment->id] = $attachment;
         $ret[$attachment->mesid][$attachment->id] = $attachment;
     }
     return $ret;
 }