Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automaticly showing inline Images in Post Body #159

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
24 changes: 24 additions & 0 deletions include/class.ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,30 @@ function deleteAttachments(){

return $deleted;
}

function inlineAttachments($text, $ref_id=0)
{
$attachments = $this->getAttachmentUrls($ref_id,'M');
$text = preg_replace("/\[.*cid\:(.*\.(png|jpg|jpeg|gif))@.*\]/e",
'"<a href=\"" . $attachments["$1"]."\"><img class=\"ineline_image\" src=\"" . $attachments["$1"]."\" ></a>"',$text);
$text = preg_replace("/\(Embedded image moved to file:\s(.*\.(png|jpg|jpeg|gif))\)/e",
'"<a href=\"" . $attachments["$1"]."\"><img class=\"ineline_image\" src=\"" . $attachments["$1"]."\" ></a>"',$text);
return $text;
}

function getAttachmentUrls($refId, $type) {

$array=array();
foreach($this->getAttachments($refId, $type) as $attachment ) {
/* The has here can be changed but must match validation in attachment.php */
$hash=md5($attachment['file_id'].session_id().$attachment['file_hash']);
$file_name = $attachment['name'];
$array[$file_name] = sprintf('attachment.php?id=%d&h=%s',
$attachment['attach_id'], $hash);
}

return $array;
}


function delete(){
Expand Down
2 changes: 1 addition & 1 deletion include/staff/ticket-view.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
<th width="440"><span><?php echo Format::htmlchars($entry['title']); ?></span></th>
<th width="300" class="tmeta"><?php echo Format::htmlchars($entry['poster']); ?></th>
</tr>
<tr><td colspan=3><?php echo Format::display($entry['body']); ?></td></tr>
<tr><td colspan=3><?php echo $ticket->inlineAttachments(Format::display($entry['body']), $entry['id']); ?></td></tr>
<?php
if($entry['attachments'] && ($links=$ticket->getAttachmentsLinks($entry['id'], $entry['thread_type']))) {?>
<tr>
Expand Down
4 changes: 4 additions & 0 deletions scp/css/scp.css
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,10 @@ time {
border:1px solid #a00;
}

.ineline_image {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you misspell this no purpose?

max-width: 900px;
}

/* Custom css for datepicker */
.ui-datepicker-trigger {
display:inline-block;
Expand Down