Beispiel #1
0
function show_attachment($post)
{
    global $grid;
    $attachment = $post->attachment;
    if (preg_match('/\\.(jpe?g|gif|png|bmp|tiff?)$/i', $attachment->path)) {
        echo '<div id="inline-attachment">';
        show_attachment_link($attachment);
        echo '<div class="frame">';
        echo "<img src=\"{$attachment->path}\" alt=\"\">\n";
        echo '</div></div>';
        return true;
    } else {
        if (preg_match('/\\.pdf$/i', $attachment->path)) {
            $path = str_replace("'", "\\'", htmlentities($attachment->path));
            echo '<div id="inline-attachment">';
            show_attachment_link($attachment);
            $loading = _('Loading') . '...';
            echo '<div class="frame">';
            echo "<div id=\"pdf-loading\">{$loading}</div>";
            echo "<canvas id=\"pdf\"></canvas>\n";
            echo "</div><a href=\"{$attachment->path}\" class=\"button\">PDF file</a></div>";
            echo '<script src="js/pdfjs.js"></script>';
            echo '<script src="js/pdf-compatibility.js"></script>';
            echo "<script>PDFJS.workerSrc = 'js/pdfjs.js';</script>";
            return true;
        } else {
            if (preg_match('/\\.json$/i', $attachment->path)) {
                $json = file_get_contents(GRID_DIR . "/public/{$attachment->path}");
                $article = json_decode($json);
                if (!empty($article->url)) {
                    $url = parse_url($article->url);
                    $domain = $url['host'];
                    $domain = str_replace('www.', '', $domain);
                }
                $meta = '';
                $by = _('By');
                $author = empty($article->author) ? '' : "{$by} {$article->author} / ";
                if (!empty($author) || !empty($domain)) {
                    $meta = "<div class=\"meta\">\n        {$author}<a href=\"{$article->url}\">{$domain}</a>\n      </div>";
                }
                $title = !empty($article->title) ? "<h2>{$article->title}</h2>" : '';
                if (!empty($article->title) && $article->title != $post->content) {
                    $grid->db->update('message', array('content' => $article->title), $post->id);
                }
                $content = $article->content;
                if (!empty($article->images)) {
                    $dir = dirname($attachment->path);
                    foreach ($article->images as $image) {
                        $content = str_replace($image->url, "{$dir}/{$image->filename}", $content);
                    }
                }
                echo "<div id=\"article\">\n      {$title}\n      {$meta}\n      {$content}\n    </div>";
                return true;
            } else {
                if (preg_match('/\\.html$/i', $attachment->path)) {
                    $html = file_get_contents(GRID_DIR . "/public/{$attachment->path}");
                    $start = mb_strpos($html, '<!-- occupy.here article start -->', 0, 'UTF-8');
                    if ($start === false) {
                        return false;
                    }
                    $end = mb_strpos($html, '<!-- occupy.here article end -->', $start, 'UTF-8');
                    $content = mb_substr($html, $start, $end - $start, 'UTF-8');
                    $download = _('plain html');
                    echo "<div id=\"article\">\n    <a href=\"{$attachment->path}\" class=\"download-article\" target=\"_blank\">{$download}</a>\n    {$content}\n    </div>";
                    return true;
                } else {
                    if (preg_match('/\\.mp3$/i', $attachment->path)) {
                        echo "<div id=\"mp3\">\n      <audio controls>\n        <source src=\"{$attachment->path}\" type=\"audio/mpeg\">\n      </audio>\n      <a href=\"{$attachment->path}\" class=\"button\">MP3 file</a>\n      <div class=\"clear\"></div>\n    </div>";
                        return true;
                    } else {
                        if (preg_match('/\\.mp4$/i', $attachment->path)) {
                            echo "<div id=\"mp4\">\n      <video controls>\n        <source src=\"{$attachment->path}\" type=\"video/mp4\">\n      </video>\n      <a href=\"{$attachment->path}\" class=\"button\">MP4 file</a>\n    </div>";
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Beispiel #2
0
Datei: _post.php Projekt: our/net
}
?>
  <div class="container" ontouchstart="">
    <div class="text-only hidden">
      <?php 
echo htmlentities($post->content, ENT_COMPAT, 'UTF-8');
?>
    </div>
    <div class="content">
      <?php 
echo nl2br(htmlentities($post->content));
?>
    </div>
    <?php 
if (!empty($post->attachment) && empty($hide_attachment_link) && substr($post->attachment->name, -5, 5) != '.json') {
    show_attachment_link($post->attachment);
}
?>
  </div>
  <div class="author">
    <a href="u/<?php 
echo $post->user_id;
?>
" class="id"><span class="color"></span><?php 
echo get_username($post->user_id);
?>
</a>
    <a class="replies-link" href="<?php 
$url = "p/{$post->id}";
if ($post->reply_count == 0) {
    echo "{$url}#reply\">" . _('post a reply');