Beispiel #1
0
    exit(0);
} else {
    // delete any preview comment from session data:
    $Session->delete('core.preview_Comment');
}
// RECORD comment:
$result = $Comment->dbinsert();
// Create links
if ($result && !empty($preview_attachments)) {
    global $DB;
    load_class('links/model/_linkcomment.class.php', 'LinkComment');
    $order = 1;
    $FileCache =& get_FileCache();
    $attachments = explode(',', $preview_attachments);
    $final_attachments = explode(',', $checked_attachments);
    $LinkOwner = new LinkComment($Comment);
    $attachment_dir = NULL;
    // No need transaction here, because if one file can't be attached, the rest should be still attached
    foreach ($attachments as $file_ID) {
        // create links between comment and attached files
        if (in_array($file_ID, $final_attachments)) {
            // attachment checkbox was checked, create the link
            $LinkOwner->add_link($file_ID, 'aftermore', $order, false);
            $order++;
        } else {
            // attachment checkbox was not checked, remove unused uploaded file
            $unused_File = $FileCache->get_by_ID($file_ID, false);
            if ($unused_File) {
                if (empty($checked_attachments) && empty($attachment_dir)) {
                    // None of the previously attached file was checked to be attached
                    $attachment_dir = dirname($unused_File->get_full_path()) . '/';
Beispiel #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;
     }
 }
// Get allowed visibility statuses
$sharing_options = get_visibility_statuses('radio-options', $exclude_statuses);
if (count($sharing_options) == 1) {
    // Only one visibility status is available, don't show radio but set hidden field
    $Form->hidden('comment_status', $sharing_options[0][0]);
} else {
    // Display visibiliy options
    $Form->radio('comment_status', $edited_Comment->status, $sharing_options, T_('Visibility'), true);
}
// Display renderers
$comment_renderer_checkboxes = $edited_Comment->renderer_checkboxes(NULL, false);
if (!empty($comment_renderer_checkboxes)) {
    $Form->info(T_('Text Renderers'), $comment_renderer_checkboxes);
}
// Display comment attachments
$LinkOwner = new LinkComment($edited_Comment);
if ($LinkOwner->count_links()) {
    // there are attachments to display
    $Form->switch_template_parts(array('fieldset_begin' => '<tr><td class="left" valign="top"><strong>$fieldset_title$:</strong></td><td class="row2 left">'));
    $Form->begin_fieldset(T_('Attachments'));
    if ($current_User->check_perm('files', 'view')) {
        // User has permission to view files
        display_attachments($LinkOwner);
    } else {
        echo T_('You do not have permission to edit file attachments for this comment');
    }
    $Form->end_fieldset();
    $Form->switch_template_parts($disp_params['edit_form_params']);
}
$Form->begin_fieldset();
$Form->submit(array('actionArray[update]', T_('Save changes'), 'SaveButton submit'));