Esempio n. 1
0
 public function action_create_admin()
 {
     // if an admin account exists, lock down this step and redirect to the next step instead
     /** @var Users $users */
     $users = $this->getContext()->getService('users');
     $check_users = $users->getAll();
     if ($check_users['count'] > 0) {
         return new RedirectResponse($this->uri->create('install/modules'));
     }
     if ($this->getPost()) {
         $validator = new Validator();
         $validator->add('username', _i('Username'), [new Trim(), new Assert\NotBlank(), new Assert\Length(['min' => 4, 'max' => 32])])->add('email', _i('Email'), [new Trim(), new Assert\NotBlank(), new Assert\Email()])->add('password', _i('Password'), [new Trim(), new Assert\NotBlank(), new Assert\Length(['min' => 4, 'max' => 64])])->add('confirm_password', _i('Confirm Password'), [new EqualsField(['field' => _i('Password'), 'value' => $this->getPost('password')])]);
         $validator->validate($this->getPost());
         if (!$validator->getViolations()->count()) {
             $input = $validator->getFinalValues();
             $auth = new Auth($this->getContext());
             list($id, $activation_key) = $auth->createUser($input['username'], $input['password'], $input['email']);
             $auth->activateUser($id, $activation_key);
             $auth->authenticateWithId($id);
             $user = $auth->getUser();
             $user->save(['group_id' => 100]);
             // leave the module installation later in case we must do something with users
             $this->install->install_modules();
             return new RedirectResponse($this->uri->create('install/complete'));
         } else {
             $this->notices->set('warning', $validator->getViolations()->getText());
         }
     }
     $this->process('create_admin');
     $this->param_manager->setParam('method_title', _i('Admin Account'));
     $this->builder->createPartial('body', 'install/create_admin');
     return new Response($this->builder->build());
 }
Esempio n. 2
0
 public function action_language($language = 'en_EN')
 {
     $this->response->headers->setCookie(new Cookie($this->getContext(), 'language', $language, 31536000));
     if ($this->getRequest()->headers->get('referer')) {
         $url = $this->getRequest()->headers->get('referer');
     } else {
         $url = $this->uri->base();
     }
     $this->builder->createLayout('redirect')->getParamManager()->setParam('url', $url);
     $this->builder->getProps()->addTitle(_i('Changing Language'));
     return $this->response->setContent($this->builder->build());
 }
Esempio n. 3
0
 /**
  * A callback function for preg_replace_callback for external links (>>>//)
  * Notice: this function generates some class variables
  *
  * @param array $matches the matches sent by preg_replace_callback
  * @return string the complete anchor
  */
 public function processExternalLinks($matches)
 {
     // create $data object with all results from $matches
     $data = new \stdClass();
     $data->link = $matches[2];
     $data->shortname = $matches[3];
     $data->board = $this->radix_coll->getByShortname($data->shortname);
     $data->query = $matches[4];
     $build_href = ['tags' => ['open' => '', 'close' => ''], 'short_link' => '//boards.4chan.org/' . $data->shortname . '/', 'query_link' => '//boards.4chan.org/' . $data->shortname . '/res/' . $data->query, 'attributes' => '', 'backlink_attr' => ' class="backlink" data-function="highlight" data-backlink="true" data-board="' . ($data->board ? $data->board->shortname : $data->shortname) . '" data-post="' . $data->query . '"'];
     $build_href = Hook::forge('Foolz\\FoolFuuka\\Model\\Comment::processExternalLinks#var.link')->setObject($this)->setParam('data', $data)->setParam('build_href', $build_href)->execute()->get($build_href);
     if (!$data->board) {
         if ($data->query) {
             return implode('<a href="' . $build_href['query_link'] . '"' . $build_href['attributes'] . '>&gt;&gt;&gt;' . $data->link . '</a>', $build_href['tags']);
         }
         return implode('<a href="' . $build_href['short_link'] . '">&gt;&gt;&gt;' . $data->link . '</a>', $build_href['tags']);
     }
     if ($data->query) {
         return implode('<a href="' . $this->uri->create([$data->board->shortname, 'post', $data->query]) . '"' . $build_href['attributes'] . $build_href['backlink_attr'] . '>&gt;&gt;&gt;' . $data->link . '</a>', $build_href['tags']);
     }
     return implode('<a href="' . $this->uri->create($data->board->shortname) . '">&gt;&gt;&gt;' . $data->link . '</a>', $build_href['tags']);
 }
Esempio n. 4
0
 public function handleWeb()
 {
     $this->uri = $this->getContext()->getService('uri');
     $this->loader->setPublicDir(DOCROOT . 'foolframe/');
     $this->loader->setBaseUrl($this->uri->base() . 'foolframe/');
 }
Esempio n. 5
0
 /**
  * Get the remote link for media if it's not local
  *
  * @return  null|string  remote URL of local URL if not compatible with remote URL (see getLink() for return values)
  */
 public function getRemoteLink(Request $request)
 {
     if ($this->radix->archive && ($this->radix->getValue('images_url') === false || $this->radix->getValue('images_url') !== "")) {
         // ignore webkit and opera user agents
         $ua = $request->headers->get('User-Agent');
         if ($ua && preg_match('/(opera|webkit)/i', $ua)) {
             return $this->radix->getValue('images_url') . $this->media->media_orig;
         }
         return $this->uri->create([$this->radix->shortname, 'redirect']) . $this->media->media_orig;
     } else {
         if (file_exists($this->getDir()) !== false) {
             return $this->getLink($request);
         }
     }
 }
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\Foolfuuka\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\Foolfuuka\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\Foolfuuka\Model\BoardThreadNotFoundException $e) {
                 return $this->error(_i('Thread not found.'));
             } catch (\Foolz\Foolfuuka\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;
 }
Esempio n. 7
0
 /**
  * Adds a new report to the database
  *
  * @param   \Foolz\Foolslide\Model\Radix  $radix  The Radix to which the Report is referred to
  * @param   int     $id           The ID of the object being reported (doc_id or media_id)
  * @param   string  $reason       The reason for the report
  * @param   string  $ip_reporter  The IP in decimal format
  * @param   string  $mode         The type of column (doc_id or media_id)
  *
  * @return  \Foolz\Foolslide\Model\Report   The created report
  * @throws  ReportMediaNotFoundException    If the reported media_id doesn't exist
  * @throws  ReportCommentNotFoundException  If the reported doc_id doesn't exist
  * @throws  ReportReasonTooLongException    If the reason inserted was too long
  * @throws  ReportSentTooManyException      If the user sent too many moderation in a timeframe
  * @throws  ReportReasonNullException       If the report reason is null
  * @throws  ReportAlreadySubmittedException If the reporter’s IP has already submitted a report for the post.
  * @throws  ReportSubmitterBannedException  If the reporter’s IP has been banned.
  */
 public function p_add($radix, $id, $reason, $ip_reporter, $mode = 'doc_id')
 {
     $new = new Report($this->getContext());
     $new->radix = $radix;
     $new->board_id = $radix->id;
     if ($mode === 'media_id') {
         try {
             $this->media_factory->getByMediaId($new->radix, $id);
         } catch (MediaNotFoundException $e) {
             throw new ReportMediaNotFoundException(_i('The media file you are reporting could not be found.'));
         }
         $new->media_id = (int) $id;
     } else {
         try {
             Board::forge($this->getContext())->getPost()->setRadix($new->radix)->setOptions('doc_id', $id)->getComments();
         } catch (BoardException $e) {
             throw new ReportCommentNotFoundException(_i('The post you are reporting could not be found.'));
         }
         $new->doc_id = (int) $id;
     }
     if (trim($reason) === null) {
         throw new ReportReasonNullException(_i('A reason must be included with your report.'));
     }
     if (mb_strlen($reason, 'utf-8') > 2048) {
         throw new ReportReasonTooLongException(_i('The reason for you report was too long.'));
     }
     $new->reason = $reason;
     $new->ip_reporter = $ip_reporter;
     // check how many moderation have been sent in the last hour to prevent spam
     $row = $this->dc->qb()->select('COUNT(*) as count')->from($this->dc->p('reports'), 'r')->where('created > :time')->andWhere('ip_reporter = :ip_reporter')->setParameter(':time', time() - 86400)->setParameter(':ip_reporter', $new->ip_reporter)->execute()->fetch();
     if ($row['count'] > 25) {
         throw new ReportSentTooManyException(_i('You have submitted too many reports within an hour.'));
     }
     $reported = $this->dc->qb()->select('COUNT(*) as count')->from($this->dc->p('reports'), 'r')->where('board_id = :board_id')->andWhere('ip_reporter = :ip_reporter')->andWhere('doc_id = :doc_id')->setParameters([':board_id' => $new->board_id, ':doc_id' => $new->doc_id, ':ip_reporter' => $new->ip_reporter])->execute()->fetch();
     if ($reported['count'] > 0) {
         throw new ReportSubmitterBannedException(_i('You can only submit one report per post.'));
     }
     if ($ban = $this->ban_factory->isBanned($new->ip_reporter, $new->radix)) {
         if ($ban->board_id == 0) {
             $banned_string = _i('It looks like you were banned on all boards.');
         } else {
             $banned_string = _i('It looks like you were banned on /' . $new->radix->shortname . '/.');
         }
         if ($ban->length) {
             $banned_string .= ' ' . _i('This ban will last until:') . ' ' . date(DATE_COOKIE, $ban->start + $ban->length) . '.';
         } else {
             $banned_string .= ' ' . _i('This ban will last forever.');
         }
         if ($ban->reason) {
             $banned_string .= ' ' . _i('The reason for this ban is:') . ' «' . $ban->reason . '».';
         }
         if ($ban->appeal_status == Ban::APPEAL_NONE) {
             $banned_string .= ' ' . _i('If you\'d like to appeal to your ban, go to the :appeal page.', '<a href="' . $this->uri->create($new->radix->shortname . '/appeal') . '">' . _i('appeal') . '</a>');
         } elseif ($ban->appeal_status == Ban::APPEAL_PENDING) {
             $banned_string .= ' ' . _i('Your appeal is pending.');
         }
         throw new ReportSubmitterBannedException($banned_string);
     }
     $new->created = time();
     $this->dc->getConnection()->insert($this->dc->p('reports'), ['board_id' => $new->board_id, 'doc_id' => $new->doc_id, 'media_id' => $new->media_id, 'reason' => $new->reason, 'ip_reporter' => $new->ip_reporter, 'created' => $new->created]);
     $this->clearCache();
     return $new;
 }
Esempio n. 8
0
 /**
  * Returns the sidebar array
  */
 public function getSidebar(Request $request, $array)
 {
     $segments = explode('/', $request->getPathInfo());
     // not logged in users don't need the sidebar
     if (!$this->getAuth()->hasAccess('maccess.user')) {
         return [];
     }
     $result = [];
     foreach ($array as $key => $item) {
         if ($this->getAuth()->hasAccess('maccess.' . $item['level']) && !empty($item)) {
             $subresult = $item;
             // segment 2 contains what's currently active so we can set it lighted up
             if (isset($segments[2]) && $segments[2] == $key) {
                 $subresult['active'] = true;
             } else {
                 $subresult['active'] = false;
             }
             // we'll cherry-pick the content next
             unset($subresult['content']);
             // recognize plain URLs
             if (substr($item['default'], 0, 7) == 'http://' || substr($item['default'], 0, 8) == 'https://') {
                 // nothing to do here, just copy the URL
                 $subresult['href'] = $item['default'];
             } else {
                 // else these are internal URIs
                 // what if it uses more segments or is even an array?
                 if (!is_array($item['default'])) {
                     $default_uri = explode('/', $item['default']);
                 } else {
                     $default_uri = $item['default'];
                 }
                 array_unshift($default_uri, 'admin', $key);
                 $subresult['href'] = $this->uri->create(implode('/', $default_uri));
             }
             $subresult['content'] = [];
             // cherry-picking subfunctions
             foreach ($item['content'] as $subkey => $subitem) {
                 $subsubresult = $subitem;
                 if ($this->getAuth()->hasAccess('maccess.' . $subitem['level'])) {
                     if ($subresult['active'] && (isset($segments[2]) && $segments[3] == $subkey || isset($subitem['alt_highlight']) && in_array($segments[3], $subitem['alt_highlight']))) {
                         $subsubresult['active'] = true;
                     } else {
                         $subsubresult['active'] = false;
                     }
                     // recognize plain URLs
                     if (substr($subkey, 0, 7) == 'http://' || substr($subkey, 0, 8) == 'https://') {
                         // nothing to do here, just copy the URL
                         $subsubresult['href'] = $subkey;
                     } else {
                         // else these are internal URIs
                         // what if it uses more segments or is even an array?
                         if (!is_array($subkey)) {
                             $default_uri = explode('/', $subkey);
                         } else {
                             $default_uri = $subkey;
                         }
                         array_unshift($default_uri, 'admin', $key);
                         $subsubresult['href'] = $this->uri->create(implode('/', $default_uri));
                     }
                     $subresult['content'][] = $subsubresult;
                 }
             }
             $result[] = $subresult;
         }
     }
     return $result;
 }
Esempio n. 9
0
    public function radix_statistics($report = null)
    {
        // Load Statistics Model
        if (is_null($report)) {
            $stats = $this->board_stats->getAvailableStats();
            // Set template variables required to build the HTML.
            $this->builder->getProps()->addTitle(_i('Statistics'));
            $this->param_manager->setParam('section_title', _i('Statistics'));
            ob_start();
            ?>

            <div style="margin: 20px auto; width:960px;">
                <nav style="margin-top:20px;">
                    <ul>
                        <?php 
            foreach ($stats as $key => $stat) {
                ?>
                            <li>
                                <a href="<?php 
                echo $this->uri->create([$this->radix->shortname, 'statistics', $key]);
                ?>
"
                                   title="<?php 
                echo htmlspecialchars($stat['name']);
                ?>
"><?php 
                echo $stat['name'];
                ?>
</a>
                            </li>
                        <?php 
            }
            ?>
                    </ul>
                </nav>
            </div>

            <?php 
            $string = ob_get_clean();
            $partial = $this->builder->createPartial('body', 'plugin');
            $partial->getParamManager()->setParam('content', $string);
            return new Response($this->builder->build());
        } else {
            $stats = $this->board_stats->checkAvailableStats($report, $this->radix);
            if (!is_array($stats)) {
                return $this->error(_i('Statistic currently not available.'));
            }
            $this->builder->getProps()->addTitle(_i('Statistics') . ': ' . $stats['info']['name']);
            if (isset($stats['info']['frequency'])) {
                $last_updated = time() - $stats['timestamp'];
                if ($last_updated < 0) {
                    $last_updated = _i('now!');
                } elseif ($last_updated < 60) {
                    $last_updated = $last_updated . ' ' . _i('seconds');
                } elseif ($last_updated < 3600) {
                    $last_updated = floor($last_updated / 60) . ' ' . _i('minutes');
                } elseif ($last_updated < 86400) {
                    $last_updated = floor($last_updated / 3600) . ' ' . _i('hours');
                } else {
                    $last_updated = floor($last_updated / 86400) . ' ' . _i('days');
                }
                $section_title = sprintf(_i('Statistics: %s (Last Updated: %s ago)'), $stats['info']['name'], $last_updated);
            } else {
                $section_title = sprintf(_i('Statistics: %s'), $stats['info']['name']);
            }
            $this->param_manager->setParam('section_title', $section_title);
            $data = $stats['data'];
            $info = $stats['info'];
            ob_start();
            ?>
            <link href="<?php 
            echo $this->plugin->getAssetManager()->getAssetLink('style.css');
            ?>
" rel="stylesheet"
                  type="text/css"/>
            <div style="margin: 20px auto; width:960px;">
                <?php 
            include __DIR__ . '/../../views/' . $stats['info']['interface'] . '.php';
            ?>
            </div>
            <?php 
            $string = ob_get_clean();
            $partial = $this->builder->createPartial('body', 'plugin');
            $partial->getParamManager()->setParam('content', $string);
            return new Response($this->builder->build());
        }
    }