コード例 #1
0
ファイル: _comment.class.php プロジェクト: ldanielz/uesp.blog
 /**
  * Template function: display content of comment
  *
  * @param string Output format, see {@link format_to_output()}
  * @param boolean Add ban url action icon after each url or not
  * @param boolean show comment attachments
  * @param array attachment display params
  */
 function content($format = 'htmlbody', $ban_urls = false, $show_attachments = true, $params = array())
 {
     global $current_User;
     global $Plugins;
     // Make sure we are not missing any param:
     $params = array_merge(array('before_image' => '<div class="image_block">', 'before_image_legend' => '<div class="image_legend">', 'after_image_legend' => '</div>', 'after_image' => '</div>', 'image_size' => 'fit-400x320', 'image_text' => '', 'attachments_mode' => 'read', 'attachments_view_text' => ''), $params);
     $attachments = array();
     if ($show_attachments) {
         if (empty($this->ID) && isset($this->checked_attachments)) {
             // PREVIEW
             $attachment_ids = explode(',', $this->checked_attachments);
             $FileCache =& get_FileCache();
             foreach ($attachment_ids as $ID) {
                 $File = $FileCache->get_by_ID($ID, false, false);
                 if ($File != NULL) {
                     $attachments[] = $File;
                 }
             }
         } else {
             // Get links
             $LinkCache =& get_LinkCache();
             $commentLinks = $LinkCache->get_by_comment_ID($this->ID);
             if (!empty($commentLinks)) {
                 foreach ($commentLinks as $Link) {
                     $File = $Link->get_File();
                     $attachments[] = $File;
                 }
             }
         }
     }
     $images_is_attached = false;
     foreach ($attachments as $index => $attachment) {
         $r = '';
         $params['File'] = $attachment;
         $params['data'] =& $r;
         if (count($Plugins->trigger_event_first_true('RenderCommentAttachment', $params)) != 0) {
             echo $r;
             unset($attachments[$index]);
             continue;
         }
         if ($attachment->is_image()) {
             if ($params['attachments_mode'] == 'view') {
                 // Only preview attachments
                 $image_link_rel = '';
                 $image_link_to = '';
             } else {
                 // Read attachments
                 $image_link_rel = 'lightbox[c' . $this->ID . ']';
                 $image_link_to = 'original';
             }
             echo $attachment->get_tag($params['before_image'], $params['before_image_legend'], $params['after_image_legend'], $params['after_image'], $params['image_size'], $image_link_to, T_('Posted by ') . $this->get_author_name(), $image_link_rel);
             unset($attachments[$index]);
             $images_is_attached = true;
         }
     }
     if ($images_is_attached && $params['image_text'] != '') {
         // Display info text below pictures
         echo $params['image_text'];
     }
     if ($ban_urls) {
         // add ban icons if user has edit permission for this comment
         $ban_urls = $current_User->check_perm('comment!CURSTATUS', 'edit', false, $this);
     }
     if ($ban_urls) {
         // ban urls and user has permission
         echo add_ban_icons($this->get_content($format));
     } else {
         // don't ban urls
         echo $this->get_content($format);
     }
     if (isset($attachments)) {
         // show not image attachments
         $after_docs = '';
         if (count($attachments) > 0) {
             echo '<br /><b>' . T_('Attachments:') . '</b>';
             echo '<ul class="bFiles">';
             $after_docs = '</ul>';
         }
         foreach ($attachments as $doc_File) {
             if ($params['attachments_mode'] == 'view') {
                 // Only preview attachments
                 $attachment_download_link = '';
                 $attachment_name = $doc_File->get_type();
             } else {
                 // Read attachments
                 $attachment_download_link = action_icon(T_('Download file'), 'download', $doc_File->get_url(), '', 5) . ' ';
                 $attachment_name = $doc_File->get_view_link($doc_File->get_name());
             }
             echo '<li>';
             echo $attachment_download_link;
             echo $attachment_name;
             echo ' (' . bytesreadable($doc_File->get_size()) . ')';
             if (!empty($params['attachments_view_text'])) {
                 echo $params['attachments_view_text'];
             }
             echo '</li>';
         }
         echo $after_docs;
     }
 }
コード例 #2
0
 /**
  * Template function: display content of comment
  *
  * @param string Output format, see {@link format_to_output()}
  * @param boolean Add ban url action icon after each url or not
  * @param boolean show comment attachments
  * @param array attachment display params
  */
 function content($format = 'htmlbody', $ban_urls = false, $show_attachments = true, $params = array())
 {
     global $current_User;
     global $Plugins;
     // Make sure we are not missing any param:
     $params = array_merge(array('before_image' => '<figure class="evo_image_block">', 'before_image_legend' => '<figcaption class="evo_image_legend">', 'after_image_legend' => '</figcaption>', 'after_image' => '</figure>', 'image_size' => 'fit-400x320', 'image_class' => '', 'image_text' => '', 'attachments_mode' => 'read', 'attachments_view_text' => ''), $params);
     $attachments = array();
     if ($show_attachments) {
         if (empty($this->ID) && isset($this->checked_attachments)) {
             // PREVIEW
             $attachment_ids = explode(',', $this->checked_attachments);
             $FileCache =& get_FileCache();
             foreach ($attachment_ids as $ID) {
                 $File = $FileCache->get_by_ID($ID, false, false);
                 if ($File != NULL) {
                     $attachments[] = $File;
                 }
             }
         } else {
             // Get all Links
             $LinkOwner = new LinkComment($this);
             $attachments =& $LinkOwner->get_Links();
         }
     }
     $images_above_content = '';
     $images_below_content = '';
     foreach ($attachments as $index => $attachment) {
         if (!empty($this->ID)) {
             // Normal mode when comment exists in DB (NOT PREVIEW mode)
             $Link = $attachment;
             $link_position = $Link->get('position');
             $params['Link'] = $Link;
             $attachment = $attachment->get_File();
         } else {
             // Set default position for preview files
             $link_position = 'aftermore';
         }
         $File = $attachment;
         if (empty($File)) {
             // File object doesn't exist in DB
             global $Debuglog;
             $Debuglog->add(sprintf('File object linked to comment #%d does not exist in DB!', $this->ID), array('error', 'files'));
             continue;
         }
         if (!$File->exists()) {
             // File doesn't exist on the disk
             global $Debuglog;
             $Debuglog->add(sprintf('File linked to comment #%d does not exist (%s)!', $this->ID, $File->get_full_path()), array('error', 'files'));
             continue;
         }
         $r = '';
         $params['File'] = $File;
         $params['Comment'] = $this;
         $params['data'] =& $r;
         $temp_params = $params;
         foreach ($params as $param_key => $param_value) {
             // Pass all params by reference, in order to give possibility to modify them by plugin
             // So plugins can add some data before/after image tag (E.g. used by infodots plugin)
             $params[$param_key] =& $params[$param_key];
         }
         if (count($Plugins->trigger_event_first_true('RenderCommentAttachment', $params)) != 0) {
             // File was processed by plugin
             if ($link_position == 'teaser') {
                 // Image should be displayed above content
                 $images_above_content .= $r;
             } else {
                 // Image should be displayed below content
                 $images_below_content .= $r;
             }
             unset($attachments[$index]);
             continue;
         }
         if ($File->is_image()) {
             // File is image
             if ($params['attachments_mode'] == 'view') {
                 // Only preview attachments
                 $image_link_rel = '';
                 $image_link_to = '';
             } else {
                 // Read attachments
                 $image_link_rel = 'lightbox[c' . $this->ID . ']';
                 $image_link_to = 'original';
             }
             if (empty($this->ID)) {
                 // PREVIEW mode
                 $r = $File->get_tag($params['before_image'], $params['before_image_legend'], $params['after_image_legend'], $params['after_image'], $params['image_size'], $image_link_to, T_('Posted by ') . $this->get_author_name(), $image_link_rel, $params['image_class'], '', '', '#');
             } else {
                 $r = $Link->get_tag(array_merge(array('image_link_to' => $image_link_to, 'image_link_title' => T_('Posted by ') . $this->get_author_name(), 'image_link_rel' => $image_link_rel), $params));
             }
             if ($link_position == 'teaser') {
                 // Image should be displayed above content
                 $images_above_content .= $r;
             } else {
                 // Image should be displayed below content
                 $images_below_content .= $r;
             }
             unset($attachments[$index]);
         }
         $params = $temp_params;
     }
     if (!empty($images_above_content)) {
         // Display images above content
         echo $images_above_content;
         if ($params['image_text'] != '') {
             // Display info text below pictures
             echo $params['image_text'];
         }
     }
     if ($ban_urls) {
         // add ban icons if user has edit permission for this comment
         $ban_urls = $current_User->check_perm('comment!CURSTATUS', 'edit', false, $this);
     }
     if ($ban_urls) {
         // ban urls and user has permission
         echo add_ban_icons($this->get_content($format));
     } else {
         // don't ban urls
         echo $this->get_content($format);
     }
     if (!empty($images_below_content)) {
         // Display images below content
         echo $images_below_content;
         if (empty($images_above_content) && $params['image_text'] != '') {
             // Display info text below pictures
             echo $params['image_text'];
         }
     }
     if (isset($attachments)) {
         // show not image attachments
         $after_docs = '';
         if (count($attachments) > 0) {
             echo '<br /><b>' . T_('Attachments:') . '</b>';
             echo '<ul class="bFiles">';
             $after_docs = '</ul>';
         }
         foreach ($attachments as $attachment) {
             // $attachment is a File in preview mode, but it is a Link in normal mode
             $doc_File = empty($this->ID) ? $attachment : $attachment->get_File();
             echo '<li>';
             if (empty($doc_File)) {
                 // Broken File object
                 $attachment_download_link = '';
                 $attachment_name = empty($attachment) ? '' : T_('Link ID') . '#' . $attachment->ID;
             } elseif (!$doc_File->exists()) {
                 $attachment_download_link = '';
                 $attachment_name = $doc_File->get_name();
             } elseif ($params['attachments_mode'] == 'view') {
                 // Only preview attachments
                 $attachment_download_link = '';
                 $attachment_name = $doc_File->get_type();
             } else {
                 // Read attachments
                 $attachment_download_link = action_icon(T_('Download file'), 'download', $doc_File->get_url(), '', 5) . ' ';
                 $attachment_name = $doc_File->get_view_link($doc_File->get_name());
             }
             echo $attachment_download_link;
             echo $attachment_name;
             if (!empty($doc_File) && $doc_File->exists()) {
                 // Display file size if it exists
                 echo ' (' . bytesreadable($doc_File->get_size()) . ')';
             } else {
                 // Display warning if File is broken
                 echo ' - <span class="red nowrap">' . get_icon('warning_yellow') . ' ' . T_('Missing attachment!') . '</span>';
             }
             if (!empty($params['attachments_view_text'])) {
                 echo $params['attachments_view_text'];
             }
             echo '</li>';
         }
         echo $after_docs;
     }
 }