Esempio n. 1
0
 /**
  * Loops over the unsorted comments to fetch all the backlinks
  */
 protected function loadBacklinks()
 {
     if ($this->comments_unsorted === null) {
         return;
     }
     $c = new Comment($this->getContext());
     foreach ($this->comments_unsorted as $bulk) {
         $c->setBulk($bulk);
         $c->processComment(true);
         $bulk->clean();
     }
 }
Esempio n. 2
0
 public function post_mod_actions()
 {
     if (!$this->checkCsrfToken()) {
         return $this->response->setData(['error' => _i('The security token was not found. Please try again.')]);
     }
     if (!$this->getAuth()->hasAccess('comment.mod_capcode')) {
         return $this->response->setData(['error' => _i('Access Denied.')])->setStatusCode(403);
     }
     if (!$this->check_board()) {
         return $this->response->setData(['error' => _i('No board was selected.')])->setStatusCode(422);
     }
     if ($this->getPost('action') === 'delete_report') {
         try {
             $this->report_coll->delete($this->getPost('id'));
         } catch (\Foolz\Foolslide\Model\ReportException $e) {
             return $this->response->setData(['error' => $e->getMessage()])->setStatusCode(404);
         }
         return $this->response->setData(['success' => _i('The report was deleted.')]);
     }
     if ($this->getPost('action') === 'delete_post') {
         try {
             $comments = Board::forge($this->getContext())->getPost()->setOptions('doc_id', $this->getPost('id'))->setRadix($this->radix)->getComments();
             $comment = current($comments);
             $comment = new Comment($this->getContext(), $comment);
             $comment->delete();
         } catch (\Foolz\Foolslide\Model\BoardException $e) {
             return $this->response->setData(['error' => $e->getMessage()])->setStatusCode(404);
         }
         return $this->response->setData(['success' => _i('This post was deleted.')]);
     }
     if ($this->getPost('action') === 'delete_image') {
         try {
             $media = $this->media_factory->getByMediaId($this->radix, $this->getPost('id'));
             $media = new Media($this->getContext(), CommentBulk::forge($this->radix, null, $media));
             $media->delete(true, true, true);
         } catch (\Foolz\Foolslide\Model\MediaNotFoundException $e) {
             return $this->response->setData(['error' => $e->getMessage()])->setStatusCode(404);
         }
         return $this->response->setData(['success' => _i('This image was deleted.')]);
     }
     if ($this->getPost('action') === 'ban_image_local' || $this->getPost('action') === 'ban_image_global') {
         $global = false;
         if ($this->getPost('action') === 'ban_image_global') {
             $global = true;
         }
         try {
             $media = $this->media_factory->getByMediaId($this->radix, $this->getPost('id'));
             $media = new Media($this->getContext(), CommentBulk::forge($this->radix, null, $media));
             $media->ban($global);
         } catch (\Foolz\Foolslide\Model\MediaNotFoundException $e) {
             return $this->response->setData(['error' => $e->getMessage()])->setStatusCode(404);
         }
         return $this->response->setData(['success' => _i('This image was banned.')]);
     }
     if ($this->getPost('action') === 'ban_user') {
         try {
             $this->ban_factory->add(Inet::ptod($this->getPost('ip')), $this->getPost('reason'), $this->getPost('length'), $this->getPost('board_ban') === 'global' ? array() : array($this->radix->id));
         } catch (\Foolz\Foolslide\Model\BanException $e) {
             return $this->response->setData(['error' => $e->getMessage()])->setStatusCode(404);
         }
         return $this->response->setData(['success' => _i('This user was banned.')]);
     }
 }
Esempio n. 3
0
    public function toString()
    {
        $board = $this->getParamManager()->getParam('board');
        $controller_method = $this->getBuilderParamManager()->getParam('controller_method', 'thread');
        $thread_id = $this->getBuilderParamManager()->getParam('thread_id', 0);
        foreach ($board as $key => $post) {
            if (isset($post['op'])) {
                $op_bulk = $post['op'];
                $op = new Comment($this->getContext(), $op_bulk);
                $op->setControllerMethod($controller_method);
                if ($op_bulk->media !== null) {
                    $op_media = new Media($this->getContext(), $op_bulk);
                } else {
                    $op_media = null;
                }
                $num = $op->num . ($op->subnum ? '_' . $op->subnum : '');
                ?>
        <?php 
                if ($thread_id === 0) {
                    ?>
        <div class="thread stub stub_doc_id_<?php 
                    echo $op->doc_id;
                    ?>
">
            <button class="btn-toggle-post" data-function="showThread" data-board="<?php 
                    echo $op->radix->shortname;
                    ?>
" data-doc-id="<?php 
                    echo $op->doc_id;
                    ?>
" data-thread-num="<?php 
                    echo $op->thread_num;
                    ?>
"><i class="icon-plus"></i></button>
            <?php 
                    if ($op->email && $op->email !== 'noko') {
                        ?>
<a href="mailto:<?php 
                        echo rawurlencode($op->email);
                        ?>
"><?php 
                    }
                    ?>
<span class="post_author"><?php 
                    echo $op->getNameProcessed();
                    ?>
</span><?php 
                    echo $op->getNameProcessed() && $op->getTripProcessed() ? ' ' : '';
                    ?>
<span class="post_tripcode"><?php 
                    echo $op->getTripProcessed();
                    ?>
</span><?php 
                    if ($op->email && $op->email !== 'noko') {
                        ?>
</a><?php 
                    }
                    ?>
            (<?php 
                    echo $post['omitted'] + 5 . ' ' . _i('replies');
                    ?>
)
        </div>
        <?php 
                }
                ?>
        <article id="<?php 
                echo $num;
                ?>
" class="clearfix thread doc_id_<?php 
                echo $op->doc_id;
                ?>
 board_<?php 
                echo $op->radix->shortname;
                ?>
" data-doc-id="<?php 
                echo $op->doc_id;
                ?>
" data-thread-num="<?php 
                echo $op->thread_num;
                ?>
">
                <?php 
                if ($thread_id === 0) {
                    ?>
                <div class="stub pull-left">
                    <button class="btn-toggle-post" data-function="hideThread" data-board="<?php 
                    echo $op->radix->shortname;
                    ?>
" data-doc-id="<?php 
                    echo $op->doc_id;
                    ?>
"><i class="icon-minus"></i></button>
                </div>
                <?php 
                }
                ?>
                <?php 
                \Foolz\Plugin\Hook::forge('foolslide.themes.default_after_op_open')->setObject($this)->setParam('board', $op->radix)->execute();
                ?>
                <?php 
                if ($op_media !== null) {
                    ?>
                <div class="thread_image_box">
                    <?php 
                    if ($op_media->getMediaStatus($this->getRequest()) === 'banned') {
                        ?>
                    <img src="<?php 
                        echo $this->getAssetManager()->getAssetLink('images/banned-image.png');
                        ?>
" width="150" height="150" />
                    <?php 
                    } elseif ($op_media->getMediaStatus($this->getRequest()) !== 'normal') {
                        ?>
                    <a href="<?php 
                        echo $op_media->getMediaLink($this->getRequest()) ? $op_media->getMediaLink($this->getRequest()) : $op_media->getRemoteMediaLink($this->getRequest());
                        ?>
" target="_blank" rel="noreferrer" class="thread_image_link">
                        <img src="<?php 
                        echo $this->getAssetManager()->getAssetLink('images/missing-image.jpg');
                        ?>
" width="150" height="150" />
                    </a>
                    <?php 
                    } else {
                        ?>
                    <a href="<?php 
                        echo $op_media->getMediaLink($this->getRequest()) ? $op_media->getMediaLink($this->getRequest()) : $op_media->getRemoteMediaLink($this->getRequest());
                        ?>
" target="_blank" rel="noreferrer" class="thread_image_link">
                        <?php 
                        if (!$this->getAuth()->hasAccess('maccess.mod') && !$op->radix->getValue('transparent_spoiler') && $op_media->spoiler) {
                            ?>
                        <div class="spoiler_box"><span class="spoiler_box_text"><?php 
                            echo _i('Spoiler');
                            ?>
<span class="spoiler_box_text_help"><?php 
                            echo _i('Click to view');
                            ?>
</span></div>
                        <?php 
                        } else {
                            ?>
                        <img src="<?php 
                            echo $op_media->getThumbLink($this->getRequest());
                            ?>
" width="<?php 
                            echo $op_media->preview_w;
                            ?>
" height="<?php 
                            echo $op_media->preview_h;
                            ?>
" class="thread_image<?php 
                            echo $op_media->spoiler ? ' is_spoiler_image' : '';
                            ?>
" data-md5="<?php 
                            echo $op_media->media_hash;
                            ?>
" />
                        <?php 
                        }
                        ?>
                    </a>
                    <?php 
                    }
                    ?>
                    <?php 
                    if ($op_media->getMediaStatus($this->getRequest()) !== 'banned') {
                        ?>
                    <div class="post_file" style="padding-left: 2px;<?php 
                        if ($op_media->preview_w > 149) {
                            echo 'max-width:' . $op_media->preview_w . 'px;';
                        }
                        ?>
">
                        <?php 
                        echo ByteSize::formatBinary($op_media->media_size, 0) . ', ' . $op_media->media_w . 'x' . $op_media->media_h . ', ';
                        ?>
<a class="post_file_filename" href="<?php 
                        echo $op_media->getMediaLink($this->getRequest()) ? $op_media->getMediaLink($this->getRequest()) : $op_media->getRemoteMediaLink($this->getRequest());
                        ?>
" target="_blank"><?php 
                        echo $op_media->getMediaFilenameProcessed();
                        ?>
</a>
                    </div>
                    <?php 
                    }
                    ?>
                    <div class="post_file_controls">
                        <?php 
                    if ($op_media->getMediaStatus($this->getRequest()) !== 'banned' || $this->getAuth()->hasAccess('media.see_banned')) {
                        ?>
                        <?php 
                        if (!$op->radix->hide_thumbnails || $this->getAuth()->hasAccess('maccess.mod')) {
                            ?>
                            <a href="<?php 
                            echo $this->getUri()->create($op->radix->shortname . '/search/image/' . $op_media->getSafeMediaHash());
                            ?>
" class="btnr parent"><?php 
                            echo _i('View Same');
                            ?>
</a><a
                                href="http://google.com/searchbyimage?image_url=<?php 
                            echo $op_media->getThumbLink($this->getRequest());
                            ?>
" target="_blank"
                                class="btnr parent">Google</a><a
                                href="http://iqdb.org/?url=<?php 
                            echo $op_media->getThumbLink($this->getRequest());
                            ?>
" target="_blank"
                                class="btnr parent">iqdb</a><a
                                href="http://saucenao.com/search.php?url=<?php 
                            echo $op_media->getThumbLink($this->getRequest());
                            ?>
" target="_blank"
                                class="btnr parent">SauceNAO</a><?php 
                            if (!$op->radix->archive || $op->radix->getValue('archive_full_images')) {
                                ?>
<a
                                href="<?php 
                                echo $op_media->getMediaDownloadLink($this->getRequest());
                                ?>
" download="<?php 
                                echo $op_media->getMediaFilenameProcessed();
                                ?>
"
                                class="btnr parent"><i class="icon-download-alt"></i></a><?php 
                            }
                            ?>
                            <?php 
                        }
                        ?>
                        <?php 
                    }
                    ?>
                    </div>
                </div>
                <?php 
                }
                ?>
                <header>
                    <div class="post_data">
                        <?php 
                if ($op->getTitleProcessed() !== '') {
                    ?>
<h2 class="post_title"><?php 
                    echo $op->getTitleProcessed();
                    ?>
</h2><?php 
                }
                ?>
                        <span class="post_poster_data">
                            <?php 
                if ($op->email && $op->email !== 'noko') {
                    ?>
<a href="mailto:<?php 
                    echo rawurlencode($op->email);
                    ?>
"><?php 
                }
                ?>
<span class="post_author"><?php 
                echo $op->getNameProcessed();
                ?>
</span><?php 
                echo $op->getNameProcessed() && $op->getTripProcessed() ? ' ' : '';
                ?>
<span class="post_tripcode"><?php 
                echo $op->getTripProcessed();
                ?>
</span><?php 
                if ($op->email && $op->email !== 'noko') {
                    ?>
</a><?php 
                }
                ?>

                            <?php 
                if ($op->getPosterHashProcessed()) {
                    ?>
<span class="poster_hash">ID:<?php 
                    echo $op->getPosterHashProcessed();
                    ?>
</span><?php 
                }
                ?>
                            <?php 
                if ($op->capcode !== 'N') {
                    ?>
                            <?php 
                    if ($op->capcode === 'M') {
                        ?>
<span class="post_level post_level_moderator">## <?php 
                        echo _i('Mod');
                        ?>
</span><?php 
                    }
                    ?>
                            <?php 
                    if ($op->capcode === 'A') {
                        ?>
<span class="post_level post_level_administrator">## <?php 
                        echo _i('Admin');
                        ?>
</span><?php 
                    }
                    ?>
                            <?php 
                    if ($op->capcode === 'D') {
                        ?>
<span class="post_level post_level_developer">## <?php 
                        echo _i('Developer');
                        ?>
</span><?php 
                    }
                    ?>
                            <?php 
                }
                ?>
                        </span>
                        <span class="time_wrap">
                            <time datetime="<?php 
                echo gmdate(DATE_W3C, $op->timestamp);
                ?>
" class="show_time" <?php 
                if ($op->radix->archive) {
                    ?>
 title="<?php 
                    echo _i('4chan Time') . ': ' . $op->getFourchanDate();
                    ?>
"<?php 
                }
                ?>
><?php 
                echo gmdate('D d M H:i:s Y', $op->timestamp);
                ?>
</time>
                        </span>
                        <a href="<?php 
                echo $this->getUri()->create(array($op->radix->shortname, $controller_method, $op->thread_num)) . '#' . $num;
                ?>
" data-post="<?php 
                echo $num;
                ?>
" data-function="highlight">No.</a><a href="<?php 
                echo $this->getUri()->create(array($op->radix->shortname, $controller_method, $op->thread_num)) . '#q' . $num;
                ?>
" data-post="<?php 
                echo $num;
                ?>
" data-function="quote"><?php 
                echo $num;
                ?>
</a>

                        <span class="post_type">
                            <?php 
                if ($op->poster_country !== null) {
                    ?>
<span title="<?php 
                    echo e($op->poster_country_name);
                    ?>
" class="flag flag-<?php 
                    echo strtolower($op->poster_country);
                    ?>
"></span><?php 
                }
                ?>
                            <?php 
                if (isset($op_media) && $op_media->spoiler) {
                    ?>
<i class="icon-eye-close" title="<?php 
                    echo htmlspecialchars(_i('The image in this post has been marked spoiler.'));
                    ?>
"></i><?php 
                }
                ?>
                            <?php 
                if ($op->deleted && !$op->timestamp_expired) {
                    ?>
<i class="icon-trash" title="<?php 
                    echo htmlspecialchars(_i('This thread was prematurely deleted.'));
                    ?>
"></i><?php 
                }
                ?>
                            <?php 
                if ($op->deleted && $op->timestamp_expired) {
                    ?>
<i class="icon-trash" title="<?php 
                    echo htmlspecialchars(_i('This thread was deleted on %s.', gmdate('M d, Y \\a\\t H:i:s e', $op->timestamp_expired)));
                    ?>
"></i><?php 
                }
                ?>
                            <?php 
                if ($op->sticky) {
                    ?>
<i class="icon-pushpin" title="<?php 
                    echo _i('This thread has been stickied.');
                    ?>
"></i><?php 
                }
                ?>
                            <?php 
                if ($op->locked) {
                    ?>
<i class="icon-lock" title="<?php 
                    echo _i('This thread has been locked.');
                    ?>
"></i><?php 
                }
                ?>
                        </span>

                        <span class="post_controls">
                <a href="<?php 
                echo $this->getUri()->create(array($op->radix->shortname, 'thread', $num));
                ?>
" class="btnr parent"><?php 
                echo _i('View');
                ?>
</a><a href="<?php 
                echo $this->getUri()->create(array($op->radix->shortname, $controller_method, $num)) . '#reply';
                ?>
" class="btnr parent"><?php 
                echo _i('Reply');
                ?>
</a><?php 
                echo isset($post['omitted']) && $post['omitted'] > 50 ? '<a href="' . $this->getUri()->create($op->radix->shortname . '/last/50/' . $num) . '" class="btnr parent">' . _i('Last 50') . '</a>' : '';
                echo $op->radix->archive ? '<a href="//boards.4chan.org/' . $op->radix->shortname . '/thread/' . $num . '" class="btnr parent">' . _i('Original') . '</a>' : '';
                ?>
<a href="#" class="btnr parent" data-post="<?php 
                echo $op->doc_id;
                ?>
" data-post-id="<?php 
                echo $num;
                ?>
" data-board="<?php 
                echo htmlspecialchars($op->radix->shortname);
                ?>
" data-controls-modal="post_tools_modal" data-backdrop="true" data-keyboard="true" data-function="report"><?php 
                echo _i('Report');
                ?>
</a><?php 
                if ($this->getAuth()->hasAccess('maccess.mod') || !$op->radix->archive) {
                    ?>
<a href="#" class="btnr parent" data-post="<?php 
                    echo $op->doc_id;
                    ?>
" data-post-id="<?php 
                    echo $num;
                    ?>
" data-board="<?php 
                    echo htmlspecialchars($op->radix->shortname);
                    ?>
" data-controls-modal="post_tools_modal" data-backdrop="true" data-keyboard="true" data-function="delete"><?php 
                    echo _i('Delete');
                    ?>
</a><?php 
                }
                ?>
            </span>

                        <div class="backlink_list"<?php 
                echo $op->getBacklinks() ? ' style="display:block"' : '';
                ?>
>
                            <?php 
                echo _i('Quoted By:');
                ?>
 <span class="post_backlink" data-post="<?php 
                echo $num;
                ?>
"><?php 
                echo $op->getBacklinks() ? implode(' ', $op->getBacklinks()) : '';
                ?>
</span>
                        </div>

                        <?php 
                if ($this->getAuth()->hasAccess('maccess.mod')) {
                    ?>
                        <div class="btn-group" style="clear:both; padding:5px 0 0 0;">
                            <button class="btn btn-mini" data-function="activateModeration"><?php 
                    echo _i('Mod');
                    if ($op->poster_ip) {
                        echo ' ' . Inet::dtop($op->poster_ip);
                    }
                    ?>
</button>
                        </div>
                        <div class="btn-group post_mod_controls" style="clear:both; padding:5px 0 0 0;">
                            <button class="btn btn-mini" data-function="mod" data-board="<?php 
                    echo $op->radix->shortname;
                    ?>
" data-id="<?php 
                    echo $op->doc_id;
                    ?>
" data-action="delete_post"><?php 
                    echo _i('Delete Thread');
                    ?>
</button>
                            <?php 
                    if (!is_null($op_media)) {
                        ?>
                            <button class="btn btn-mini" data-function="mod" data-board="<?php 
                        echo $op->radix->shortname;
                        ?>
" data-id="<?php 
                        echo $op_media->media_id;
                        ?>
" data-doc-id="<?php 
                        echo $op->doc_id;
                        ?>
" data-action="delete_image"><?php 
                        echo _i('Delete Image');
                        ?>
</button>
                            <button class="btn btn-mini" data-function="mod" data-board="<?php 
                        echo $op->radix->shortname;
                        ?>
" data-id="<?php 
                        echo $op_media->media_id;
                        ?>
" data-doc-id="<?php 
                        echo $op->doc_id;
                        ?>
" data-action="ban_image_local"><?php 
                        echo _i('Ban Image');
                        ?>
</button>
                            <button class="btn btn-mini" data-function="mod" data-board="<?php 
                        echo $op->radix->shortname;
                        ?>
" data-id="<?php 
                        echo $op_media->media_id;
                        ?>
" data-doc-id="<?php 
                        echo $op->doc_id;
                        ?>
" data-action="ban_image_global"><?php 
                        echo _i('Ban Image Globally');
                        ?>
</button>
                            <?php 
                    }
                    ?>
                            <?php 
                    if ($op->poster_ip) {
                        ?>
                            <button class="btn btn-mini" data-function="ban" data-controls-modal="post_tools_modal" data-backdrop="true" data-keyboard="true" data-board="<?php 
                        echo $op->radix->shortname;
                        ?>
" data-ip="<?php 
                        echo Inet::dtop($op->poster_ip);
                        ?>
" data-action="ban_user"><?php 
                        echo _i('Ban IP:') . ' ' . Inet::dtop($op->poster_ip);
                        ?>
</button>
                            <button class="btn btn-mini" data-function="searchUser" data-board="<?php 
                        echo $op->radix->shortname;
                        ?>
" data-board-url="<?php 
                        echo $this->getUri()->create(array($op->radix->shortname));
                        ?>
" data-id="<?php 
                        echo $op->doc_id;
                        ?>
" data-poster-ip="<?php 
                        echo Inet::dtop($op->poster_ip);
                        ?>
"><?php 
                        echo _i('Search IP');
                        ?>
</button>
                            <?php 
                        if ($this->getPreferences()->get('foolslide.sphinx.global')) {
                            ?>
                                <button class="btn btn-mini" data-function="searchUserGlobal" data-board="<?php 
                            echo $op->radix->shortname;
                            ?>
" data-board-url="<?php 
                            echo $this->getUri()->create(array($op->radix->shortname));
                            ?>
" data-id="<?php 
                            echo $op->doc_id;
                            ?>
" data-poster-ip="<?php 
                            echo Inet::dtop($op->poster_ip);
                            ?>
"><?php 
                            echo _i('Search IP Globally');
                            ?>
</button>
                                <?php 
                        }
                        ?>
                            <?php 
                    }
                    ?>
                        </div>
                        <?php 
                }
                ?>
                    </div>
                </header>

                <div class="text<?php 
                if (preg_match('/[\\x{4E00}-\\x{9FBF}\\x{3040}-\\x{309F}\\x{30A0}-\\x{30FF}]/u', $op->getCommentProcessed())) {
                    echo ' shift-jis';
                }
                ?>
">
                    <?php 
                echo $op->getCommentProcessed();
                ?>
                </div>
                <div class="thread_tools_bottom">
                    <?php 
                if (isset($post['omitted']) && $post['omitted'] > 0) {
                    ?>
        <span class="omitted">
            <a style="display:inline-block" href="<?php 
                    echo $this->getUri()->create(array($op->radix->shortname, $controller_method, $op->thread_num));
                    ?>
" data-function="expandThread" data-thread-num="<?php 
                    echo $op->thread_num;
                    ?>
"><i class="icon icon-resize-full"></i></a>
                    <span class="omitted_text">
                <span class="omitted_posts"><?php 
                    echo $post['omitted'];
                    ?>
</span> <?php 
                    echo _n('post', 'posts', $post['omitted']);
                    ?>
                        <?php 
                    if (isset($post['images_omitted']) && $post['images_omitted'] > 0) {
                        ?>
                        <?php 
                        echo _i('and');
                        ?>
 <span class="omitted_images"><?php 
                        echo $post['images_omitted'];
                        ?>
</span> <?php 
                        echo _n('image', 'images', $post['images_omitted']);
                        ?>
                        <?php 
                    }
                    ?>
                        <?php 
                    echo _n('omitted', 'omitted', $post['omitted'] + $post['images_omitted']);
                    ?>
        </span>
                    <?php 
                }
                ?>
                </div>

                <?php 
                if ($op->getReports()) {
                    ?>
                <?php 
                    foreach ($op->getReports() as $report) {
                        ?>
                    <div class="report_reason"><?php 
                        echo '<strong>' . _i('Reported Reason:') . '</strong> ' . $report->getReasonProcessed();
                        ?>
                        <br/>
                        <div class="ip_reporter">
                            <strong><?php 
                        echo _i('Info:');
                        ?>
</strong>
                            <?php 
                        echo Inet::dtop($report->ip_reporter);
                        ?>
, <?php 
                        echo _i('Type:');
                        ?>
 <?php 
                        echo $report->media_id !== null ? _i('media') : _i('post');
                        ?>
, <?php 
                        echo _i('Time:');
                        ?>
 <?php 
                        echo gmdate('D M d H:i:s Y', $report->created);
                        ?>
                            <button class="btn btn-mini" data-function="mod" data-id="<?php 
                        echo $report->id;
                        ?>
" data-board="<?php 
                        echo htmlspecialchars($op->radix->shortname);
                        ?>
" data-action="delete_report"><?php 
                        echo _i('Delete Report');
                        ?>
</button>
                        </div>
                    </div>
                    <?php 
                    }
                    ?>
                <?php 
                }
                ?>
                <?php 
            } elseif (isset($post['posts'])) {
                ?>
        <article class="clearfix thread">
                    <?php 
                \Foolz\Plugin\Hook::forge('foolslide.themes.default_after_headless_open')->setObject($this)->setParam('board', array(isset($radix) ? $radix : null))->execute();
                ?>
                <?php 
            }
            ?>

            <aside class="posts">
                <?php 
            if (isset($post['posts'])) {
                $post_counter = 0;
                $image_counter = 0;
                $board_comment_view = $this->getBuilder()->createPartial('post', 'board_comment');
                // reusable Comment object not to create one every loop
                $comment = new Comment($this->getContext());
                $comment->setControllerMethod($controller_method);
                $media_obj = new Media($this->getContext());
                $search = array('/\\>[^\\S ]+/s', '/[^\\S ]+\\</s', '/(\\s)+/s');
                $replace = array('>', '<', '\\1');
                foreach ($post['posts'] as $p) {
                    /** @var CommentBulk $p */
                    $post_counter++;
                    if ($p->media !== null) {
                        $image_counter++;
                    }
                    if ($image_counter == 150) {
                        $modifiers['lazyload'] = true;
                    }
                    $comment->setBulk($p);
                    // set the $media to null and leave the Media object in existence
                    if ($p->media !== null) {
                        $media_obj->setBulk($p);
                        $media = $media_obj;
                    } else {
                        $media = null;
                    }
                    $board_comment_view->getParamManager()->setParams(['p' => $comment, 'p_media' => $media, 'modifiers' => $this->getBuilderParamManager()->getParam('modifiers', false), 'post_counter' => $post_counter, 'image_counter' => $image_counter]);
                    // refreshes the string
                    $board_comment_view->doBuild();
                    echo preg_replace($search, $replace, $board_comment_view->build());
                    // remove extra strings from the objects
                    $board_comment_view->clearBuilt();
                    $p->comment->clean();
                    if ($p->media !== null) {
                        $p->media->clean();
                    }
                    $this->flush();
                }
            }
            ?>
            </aside>

            <?php 
            if ($thread_id !== 0) {
                ?>
            <div class="js_hook_realtimethread"></div>
            <?php 
                echo $this->getBuilder()->isPartial('tools_reply_box') ? $this->getBuilder()->getPartial('tools_reply_box')->build() : '';
                ?>
            <?php 
            }
            ?>
            <?php 
            if (isset($post['op']) || isset($post['posts'])) {
                ?>
        </article>
        <?php 
            }
            ?>
            <?php 
        }
        ?>
        <article class="clearfix thread backlink_container">
            <div id="backlink" style="position: absolute; top: 0; left: 0; z-index: 5;"></div>
        </article>
        <?php 
    }
Esempio n. 4
0
    public function toString()
    {
        $board = $this->getParamManager()->getParam('board');
        $radix = $this->getBuilderParamManager()->getParam('radix');
        ?>
        <div id="thread_o_matic" class="clearfix">
        <?php 
        $separator = 0;
        foreach ($board as $k => $p_bulk) {
            $p = new Comment($this->getContext(), $p_bulk);
            if ($p_bulk->media !== null) {
                $p_media = new Media($this->getContext(), $p_bulk);
            } else {
                $p_media = null;
            }
            $separator++;
            ?>
        <article id="<?php 
            echo $p->num;
            ?>
" class="thread doc_id_<?php 
            echo $p->doc_id;
            ?>
">
            <header>
                <div class="post_data">
                    <h2 class="post_title"><?php 
            echo $p->getTitleProcessed();
            ?>
</h2>
                    <span class="post_author"><?php 
            echo $p->email && $p->email !== 'noko' ? '<a href="mailto:' . rawurlencode($p->email) . '">' . $p->getNameProcessed() . '</a>' : $p->getNameProcessed();
            ?>
</span>
                    <span class="post_trip"><?php 
            echo $p->getTripProcessed();
            ?>
</span>
                    <span class="poster_hash"><?php 
            echo $p->getPosterHashProcessed() ? 'ID:' . $p->getPosterHashProcessed() : '';
            ?>
</span>
                    <?php 
            if ($p->capcode == 'M') {
                ?>
                    <span class="post_level post_level_moderator">## <?php 
                echo _i('Mod');
                ?>
</span>
                    <?php 
            }
            ?>
                    <?php 
            if ($p->capcode == 'A') {
                ?>
                    <span class="post_level post_level_administrator">## <?php 
                echo _i('Admin');
                ?>
</span>
                    <?php 
            }
            ?>
                    <?php 
            if ($p->capcode == 'D') {
                ?>
                    <span class="post_level post_level_developer">## <?php 
                echo _i('Developer');
                ?>
</span>
                    <?php 
            }
            ?>
<br/>
                    <time datetime="<?php 
            echo gmdate(DATE_W3C, $p->timestamp);
            ?>
"><?php 
            echo gmdate('D M d H:i:s Y', $p->timestamp);
            ?>
</time>
                    <span class="post_number"><a href="<?php 
            echo $this->getUri()->create($radix->shortname . '/thread/' . $p->num) . '#' . $p->num;
            ?>
" data-function="highlight" data-post="<?php 
            echo $p->num;
            ?>
">No.</a><a href="<?php 
            echo $this->getUri()->create($radix->shortname . '/thread/' . $p->num) . '#q' . $p->num;
            ?>
" data-function="quote" data-post="<?php 
            echo $p->num;
            ?>
"><?php 
            echo $p->num;
            ?>
</a></span>
                    <?php 
            if ($p->poster_country !== null) {
                ?>
<span class="post_type"><span title="<?php 
                echo e($p->poster_country_name);
                ?>
" class="flag flag-<?php 
                echo strtolower($p->poster_country);
                ?>
"></span></span><?php 
            }
            ?>
                    <span class="post_controls"><a href="<?php 
            echo $this->getUri()->create($radix->shortname . '/thread/' . $p->num);
            ?>
" class="btnr parent"><?php 
            echo _i('View');
            ?>
</a><a href="<?php 
            echo $this->getUri()->create($radix->shortname . '/thread/' . $p->num) . '#reply';
            ?>
" class="btnr parent"><?php 
            echo _i('Reply');
            ?>
</a><?php 
            echo isset($p->count_all) && $p->count_all > 50 ? '<a href="' . $this->getUri()->create($radix->shortname . '/last50/' . $p->num) . '" class="btnr parent">' . _i('Last 50') . '</a>' : '';
            if ($radix->archive == 1) {
                ?>
<a href="http://boards.4chan.org/<?php 
                echo $radix->shortname . '/thread/' . $p->num;
                ?>
" class="btnr parent"><?php 
                echo _i('Original');
                ?>
</a><?php 
            }
            ?>
<a href="<?php 
            echo $this->getUri()->create($radix->shortname . '/report/' . $p->doc_id);
            ?>
" class="btnr parent" data-function="report" data-post="<?php 
            echo $p->doc_id;
            ?>
" data-post-id="<?php 
            echo $p->num;
            ?>
" data-board="<?php 
            echo htmlspecialchars($p->radix->shortname);
            ?>
" data-controls-modal="post_tools_modal" data-backdrop="true" data-keyboard="true"><?php 
            echo _i('Report');
            ?>
</a><?php 
            if ($this->getAuth()->hasAccess('maccess.mod')) {
                ?>
<a href="<?php 
                echo $this->getUri()->create($radix->shortname . '/delete/' . $p->doc_id);
                ?>
" class="btnr parent" data-function="delete" data-post="<?php 
                echo $p->doc_id;
                ?>
" data-post-id="<?php 
                echo $p->num;
                ?>
" data-board="<?php 
                echo htmlspecialchars($p->radix->shortname);
                ?>
" data-controls-modal="post_tools_modal" data-backdrop="true" data-keyboard="true"><?php 
                echo _i('Delete');
                ?>
</a><?php 
            }
            ?>
</span>
                </div>
            </header>
            <?php 
            if ($p_media !== null) {
                ?>
            <div class="thread_image_box" title="<?php 
                echo $p->getCommentProcessed() ? htmlspecialchars(strip_tags($p->getCommentProcessed())) : '';
                ?>
">
                <?php 
                if ($p_media->getMediaStatus($this->getRequest()) === 'banned') {
                    ?>
                <img src="<?php 
                    echo $this->getAssetManager()->getAssetLink('images/banned-image.png');
                    ?>
" width="150" height="150" />
                <?php 
                } elseif ($p_media->getMediaStatus($this->getRequest()) !== 'normal') {
                    ?>
                <a href="<?php 
                    echo $p_media->getMediaLink($this->getRequest()) ? $p_media->getMediaLink($this->getRequest()) : $p_media->getRemoteMediaLink($this->getRequest());
                    ?>
" target="_blank" rel="noreferrer" class="thread_image_link">
                    <img src="<?php 
                    echo $this->getAssetManager()->getAssetLink('images/missing-image.jpg');
                    ?>
" width="150" height="150" />
                </a>
                <?php 
                } else {
                    ?>
                <a href="<?php 
                    echo $this->getUri()->create($radix->shortname . '/thread/' . $p->num);
                    ?>
" rel="noreferrer" target="_blank" class="thread_image_link"<?php 
                    echo $p_media->getMediaLink($this->getRequest()) ? ' data-expand="true"' : '';
                    ?>
>
                    <?php 
                    if (!$this->getAuth()->hasAccess('maccess.mod') && !$radix->getValue('transparent_spoiler') && $p_media->spoiler) {
                        ?>
                    <div class="spoiler_box"><span class="spoiler_box_text"><?php 
                        echo _i('Spoiler');
                        ?>
<span class="spoiler_box_text_help"><?php 
                        echo _i('Click to view');
                        ?>
</span></div>
                    <?php 
                    } else {
                        ?>
                    <img src="<?php 
                        echo $p_media->getThumbLink($this->getRequest());
                        ?>
" width="<?php 
                        echo $p_media->preview_w;
                        ?>
" height="<?php 
                        echo $p_media->preview_h;
                        ?>
" data-width="<?php 
                        echo $p_media->media_w;
                        ?>
" data-height="<?php 
                        echo $p_media->media_h;
                        ?>
" data-md5="<?php 
                        echo $p_media->media_hash;
                        ?>
" class="thread_image<?php 
                        echo $p_media->spoiler ? ' is_spoiler_image' : '';
                        ?>
" />
                    <?php 
                    }
                    ?>
                </a>
                <?php 
                }
                ?>
                <?php 
                if ($p_media->getMediaStatus($this->getRequest()) !== 'banned' || $this->getAuth()->hasAccess('media.see_banned')) {
                    ?>
                <div class="post_file" style="padding-left: 2px"><?php 
                    echo \Rych\ByteSize\ByteSize::formatBinary($p_media->media_size, 0) . ', ' . $p_media->media_w . 'x' . $p_media->media_h . ', ' . $p_media->media_filename;
                    ?>
</div>
                <div class="post_file_controls">
                    <a href="<?php 
                    echo $p_media->getMediaLink($this->getRequest()) ? $p_media->getMediaLink($this->getRequest()) : $p_media->getRemoteMediaLink($this->getRequest());
                    ?>
" class="btnr" target="_blank">Full</a><a href="<?php 
                    echo $this->getUri()->create($radix->shortname . '/search/image/' . urlencode(substr($p_media->media_hash, 0, -2)));
                    ?>
" class="btnr parent"><?php 
                    echo _i('View Same');
                    ?>
</a><a target="_blank" href="http://iqdb.org/?url=<?php 
                    echo $p_media->getThumbLink($this->getRequest());
                    ?>
" class="btnr parent">iqdb</a><a target="_blank" href="http://saucenao.com/search.php?url=<?php 
                    echo $p_media->getThumbLink($this->getRequest());
                    ?>
" class="btnr parent">SauceNAO</a><a target="_blank" href="http://google.com/searchbyimage?image_url=<?php 
                    echo $p_media->getThumbLink($this->getRequest());
                    ?>
" class="btnr parent">Google</a>
                </div>
                <?php 
                }
                ?>
            </div>
            <?php 
            }
            ?>
            <div class="thread_tools_bottom">
                <?php 
            if (isset($p->comment->nreplies)) {
                ?>
                <?php 
                echo _i('Replies');
                ?>
 : <?php 
                echo $p->nreplies - 1;
                ?>
 | <?php 
                echo _i('Images');
                ?>
: <?php 
                echo $p->nimages - ($p_media !== null ? 1 : 0);
                ?>
                <?php 
            }
            ?>
                <?php 
            if ($p->deleted == 1) {
                ?>
<span class="post_type"><img src="<?php 
                echo $this->getAssetManager()->getAssetLink('images/icons/file-delete-icon.png');
                ?>
" title="<?php 
                echo htmlspecialchars(_i('This post was deleted from 4chan manually'));
                ?>
"/></span><?php 
            }
            ?>
                <?php 
            if (isset($p_media) && $p_media->spoiler == 1) {
                ?>
<span class="post_type"><img src="<?php 
                echo $this->getAssetManager()->getAssetLink('images/icons/spoiler-icon.png');
                ?>
" title="<?php 
                echo htmlspecialchars(_i('This post contains a spoiler image'));
                ?>
"/></span><?php 
            }
            ?>
            </div>
        </article>
        <?php 
            if ($separator % 4 == 0) {
                echo '<div class="clearfix"></div>';
            }
        }
        ?>
        </div>
        <article class="thread">
            <div id="backlink" class="thread_o_matic" style="position: absolute; top: 0; left: 0; z-index: 5;"></div>
        </article>
        <?php 
    }
Esempio n. 5
0
 /**
  * Delete the post and eventually the entire thread if it's OP
  * Also deletes the images when it's the only post with that image
  *
  * @param null $password
  * @param bool $force
  * @param bool $thread
  * @throws CommentSendingDatabaseException
  * @throws CommentDeleteWrongPassException
  * @return array|bool
  */
 protected function p_delete($password = null, $force = false, $thread = false)
 {
     if (!$this->getAuth()->hasAccess('comment.passwordless_deletion') && $force !== true) {
         if (!password_verify($password, $this->comment->getDelpass())) {
             throw new CommentDeleteWrongPassException(_i('You did not provide the correct deletion password.'));
         }
     }
     try {
         $this->dc->getConnection()->beginTransaction();
         // check that the post isn't already in deleted
         $has_deleted = $this->dc->qb()->select('COUNT(*) as found')->from($this->radix->getTable('_deleted'), 'd')->where('doc_id = :doc_id')->setParameter(':doc_id', $this->comment->doc_id)->execute()->fetch();
         if (!$has_deleted['found']) {
             // throw into _deleted table
             $this->dc->getConnection()->executeUpdate('INSERT INTO ' . $this->radix->getTable('_deleted') . ' ' . $this->dc->qb()->select('*')->from($this->radix->getTable(), 't')->where('doc_id = ' . $this->dc->getConnection()->quote($this->comment->doc_id))->getSQL());
         }
         // delete post
         $this->dc->qb()->delete($this->radix->getTable())->where('doc_id = :doc_id')->setParameter(':doc_id', $this->comment->doc_id)->execute();
         // purge reports
         $this->dc->qb()->delete($this->dc->p('reports'))->where('board_id = :board_id')->andWhere('doc_id = :doc_id')->setParameter(':board_id', $this->radix->id)->setParameter(':doc_id', $this->comment->doc_id)->execute();
         // clear cache
         $this->radix_coll->clearCache();
         // remove image file
         if (isset($this->media)) {
             $media_sql = $this->dc->qb()->select('COUNT(*)')->from($this->radix->getTable(), 't')->where('media_id = :media_id')->setParameter(':media_id', $this->media->media_id)->getSQL();
             $this->dc->qb()->update($this->radix->getTable('_images'))->set('total', '(' . $media_sql . ')')->where('media_id = :media_id')->setParameter(':media_id', $this->media->media_id)->execute();
             $has_image = $this->dc->qb()->select('total')->from($this->radix->getTable('_images'), 'ti')->where('media_id = :media_id')->setParameter(':media_id', $this->media->media_id)->execute()->fetch();
             if (!$has_image || !$has_image['total']) {
                 $media = new Media($this->getContext(), $this->bulk);
                 $media->delete();
             }
         }
         // if this is OP, delete replies too
         if ($this->comment->op) {
             // delete thread data
             $this->dc->qb()->delete($this->radix->getTable('_threads'))->where('thread_num = :thread_num')->setParameter(':thread_num', $this->comment->thread_num)->execute();
             // process each comment
             $comments = $this->dc->qb()->select('doc_id')->from($this->radix->getTable(), 'b')->where('thread_num = :thread_num')->setParameter(':thread_num', $this->comment->thread_num)->execute()->fetchAll();
             foreach ($comments as $comment) {
                 $post = Board::forge($this->getContext())->getPost()->setOptions('doc_id', $comment['doc_id'])->setRadix($this->radix)->getComments();
                 $post = current($post);
                 $post = new Comment($this->getContext(), $post);
                 $post->delete(null, true, true);
             }
         } else {
             // if this is not triggered by a thread deletion, update the thread table
             if ($thread === false && !$this->radix->archive) {
                 $time_last = '
                 (
                     COALESCE(GREATEST(
                         time_op,
                         (
                             SELECT MAX(timestamp) FROM ' . $this->radix->getTable() . ' xr
                             WHERE thread_num = ' . $this->dc->getConnection()->quote($this->comment->thread_num) . ' AND subnum = 0
                         )
                     ), time_op)
                 )';
                 $time_bump = '
                 (
                     COALESCE(GREATEST(
                         time_op,
                         (
                             SELECT MAX(timestamp) FROM ' . $this->radix->getTable() . ' xr
                             WHERE thread_num = ' . $this->dc->getConnection()->quote($this->comment->thread_num) . ' AND subnum = 0
                                 AND (email <> \'sage\' OR email IS NULL)
                         )
                     ), time_op)
                 )';
                 $time_ghost = '
                 (
                     SELECT MAX(timestamp) FROM ' . $this->radix->getTable() . ' xr
                     WHERE thread_num = ' . $this->dc->getConnection()->quote($this->comment->thread_num) . ' AND subnum <> 0
                 )';
                 $time_ghost_bump = '
                 (
                     SELECT MAX(timestamp) FROM ' . $this->radix->getTable() . ' xr
                     WHERE thread_num = ' . $this->dc->getConnection()->quote($this->comment->thread_num) . ' AND subnum <> 0
                         AND (email <> \'sage\' OR email IS NULL)
                 )';
                 // update thread information
                 $this->dc->qb()->update($this->radix->getTable('_threads'))->set('time_last', $time_last)->set('time_bump', $time_bump)->set('time_ghost', $time_ghost)->set('time_ghost_bump', $time_ghost_bump)->set('time_last_modified', ':time')->set('nreplies', 'nreplies - 1')->set('nimages', $this->media === null ? 'nimages' : 'nimages - 1')->where('thread_num = :thread_num')->setParameter(':time', $this->getRadixTime())->setParameter(':thread_num', $this->comment->thread_num)->execute();
             }
         }
         $this->dc->getConnection()->commit();
         // clean up some caches
         Cache::item('foolslide.model.board.getThreadComments.thread.' . md5(serialize([$this->radix->shortname, $this->comment->thread_num])))->delete();
         // clean up the 10 first pages of index and gallery that are cached
         for ($i = 1; $i <= 10; $i++) {
             Cache::item('foolslide.model.board.getLatestComments.query.' . $this->radix->shortname . '.by_post.' . $i)->delete();
             Cache::item('foolslide.model.board.getLatestComments.query.' . $this->radix->shortname . '.by_thread.' . $i)->delete();
             Cache::item('foolslide.model.board.getThreadsComments.query.' . $this->radix->shortname . '.' . $i)->delete();
         }
     } catch (\Doctrine\DBAL\DBALException $e) {
         $this->logger->error('\\Foolz\\Foolslide\\Model\\CommentInsert: ' . $e->getMessage());
         $this->dc->getConnection()->rollBack();
         throw new CommentSendingDatabaseException(_i('Something went wrong when deleting the post in the database. Try again.'));
     }
     return $this;
 }
Esempio n. 6
0
 public function submit($data, $media)
 {
     // some beginners' validation, while through validation will happen in the Comment model
     $validator = new Validator();
     $validator->add('thread_num', _i('Thread Number'), [new Assert\NotBlank()])->add('name', _i('Name'), [new Assert\Length(['max' => 64])])->add('email', _i('Email'), [new Assert\Length(['max' => 64])])->add('title', _i('Title'), [new Assert\Length(['max' => 64])])->add('delpass', _i('Deletion pass'), [new Assert\Length(['min' => 3, 'max' => 32])]);
     // no empty posts without images
     if ($media === null) {
         $validator->add('comment', _i('Comment'), [new Assert\NotBlank(), new Assert\Length(['min' => 3])]);
     }
     // this is for redirecting, not for the database
     $limit = false;
     if (isset($data['last_limit'])) {
         $limit = intval($data['last_limit']);
         unset($data['last_limit']);
     }
     $validator->validate($data);
     if (!$validator->getViolations()->count()) {
         try {
             $data['poster_ip'] = Inet::ptod($this->getRequest()->getClientIp());
             $bulk = new CommentBulk();
             $bulk->import($data, $this->radix);
             $comment = new CommentInsert($this->getContext(), $bulk);
             $comment->insert($media, $data);
         } catch (\Foolz\Foolslide\Model\CommentSendingRequestCaptchaException $e) {
             if ($this->getRequest()->isXmlHttpRequest()) {
                 return $this->response->setData(['captcha' => true]);
             } else {
                 return $this->error(_i('Your message looked like spam. Make sure you have JavaScript enabled to display the reCAPTCHA to submit the comment.'));
             }
         } catch (\Foolz\Foolslide\Model\CommentSendingException $e) {
             if ($this->getRequest()->isXmlHttpRequest()) {
                 return $this->response->setData(['error' => $e->getMessage()]);
             } else {
                 return $this->error($e->getMessage());
             }
         }
     } else {
         if ($this->getRequest()->isXmlHttpRequest()) {
             return $this->response->setData(['error' => $validator->getViolations()->getText()]);
         } else {
             return $this->error($validator->getViolations()->getHtml());
         }
     }
     if ($this->request->isXmlHttpRequest()) {
         $latest_doc_id = $this->getPost('latest_doc_id');
         if ($latest_doc_id && ctype_digit((string) $latest_doc_id)) {
             try {
                 $board = Board::forge($this->getContext())->getThread($comment->comment->thread_num)->setRadix($this->radix)->setOptions(['type' => 'from_doc_id', 'latest_doc_id' => $latest_doc_id]);
                 $comments = $board->getComments();
             } catch (\Foolz\Foolslide\Model\BoardThreadNotFoundException $e) {
                 return $this->error(_i('Thread not found.'));
             } catch (\Foolz\Foolslide\Model\BoardException $e) {
                 return $this->error(_i('Unknown error.'));
             }
             $comment_obj = new Comment($this->getContext());
             $comment_obj->setControllerMethod($limit ? 'last/' . $limit : 'thread');
             $media_obj = new Media($this->getContext());
             $m = null;
             foreach ($board->getCommentsUnsorted() as $bulk) {
                 $comment_obj->setBulk($bulk, $this->radix);
                 if ($bulk->media) {
                     $media_obj->setBulk($bulk, $this->radix);
                     $m = $media_obj;
                 } else {
                     $m = null;
                 }
                 if ($this->builder) {
                     $this->param_manager->setParam('controller_method', $limit ? 'last/' . $limit : 'thread');
                     $partial = $this->builder->createPartial('board_comment', 'board_comment');
                     $partial->getParamManager()->setParam('p', $comment_obj)->setParam('p_media', $m);
                     $bulk->comment->formatted = $partial->build();
                     $partial->clearBuilt();
                 }
             }
             $this->response->setData(['success' => _i('Message sent.')] + $comments);
         } else {
             if ($this->builder) {
                 $this->param_manager->setParam('controller_method', $limit ? 'last/' . $limit : 'thread');
                 $partial = $this->builder->createPartial('board_comment', 'board_comment');
                 $partial->getParamManager()->setParam('p', new Comment($this->getContext(), $comment->bulk))->setParam('p_media', new Media($this->getContext(), $comment->bulk));
                 $bulk->comment->formatted = $partial->build();
                 $partial->clearBuilt();
             }
             $this->response->setData(['success' => _i('Message sent.'), 'thread_num' => $comment->comment->thread_num, $comment->comment->thread_num => ['posts' => [$comment->bulk]]]);
         }
     } else {
         $this->builder->createLayout('redirect')->getParamManager()->setParam('url', $this->uri->create([$this->radix->shortname, !$limit ? 'thread' : 'last/' . $limit, $comment->comment->thread_num]) . '#' . $comment->comment->num);
         $this->builder->getProps()->addTitle(_i('Redirecting'));
         $this->response->setContent($this->builder->build());
     }
     return $this->response;
 }