public function action_board($shortname = null) { $data['form'] = $this->radix_coll->structure(); if ($this->getPost() && !$this->checkCsrfToken()) { $this->notices->set('warning', _i('The security token was not found. Please try again.')); } elseif ($this->getPost()) { $result = Validator::formValidate($data['form'], $this->getPost()); if (isset($result['error'])) { $this->notices->set('warning', $result['error']); } else { // it's actually fully checked, we just have to throw it in DB $this->radix_coll->save($result['success']); if (is_null($shortname)) { $this->notices->setFlash('success', _i('New board created!')); return $this->redirect('admin/boards/board/' . $result['success']['shortname']); } elseif ($shortname != $result['success']['shortname']) { // case in which letter was changed $this->notices->setFlash('success', _i('Board information updated.')); return $this->redirect('admin/boards/board/' . $result['success']['shortname']); } else { $this->notices->set('success', _i('Board information updated.')); } } } $board = $this->radix_coll->getByShortname($shortname); if ($board === false) { throw new NotFoundHttpException(); } $data['object'] = (object) $board->getAllValues(); $this->param_manager->setParam('method_title', [_i('Manage'), _i('Edit'), $shortname]); $this->builder->createPartial('body', 'form_creator')->getParamManager()->setParams($data); return new Response($this->builder->build()); }
protected function execute(InputInterface $input, OutputInterface $output) { if (($radix = $input->getOption('radix')) !== null) { if ($this->radix_coll->getByShortname($radix) !== false) { $this->board_statistics($output, $radix); } else { $output->writeln('<error>' . _i('Wrong radix (board short name) specified.') . '</error>'); } } else { $this->board_statistics($output); } }
/** * Commodity to check that the shortname is not wrong and return a coherent error */ protected function check_board() { $board = $this->getQuery('board', $this->getPost('board', null)); if ($board === null) { return false; } if (!($this->radix = $this->radix_coll->getByShortname($board))) { return false; } return true; }
/** * 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\\Foolslide\\Model\\Comment::processExternalLinks.result.html')->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'] . '>>>>' . $data->link . '</a>', $build_href['tags']); } return implode('<a href="' . $build_href['short_link'] . '">>>>' . $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'] . '>>>>' . $data->link . '</a>', $build_href['tags']); } return implode('<a href="' . $this->uri->create($data->board->shortname) . '">>>>' . $data->link . '</a>', $build_href['tags']); }
/** * Gets the search results * * @return \Foolz\Foolslide\Model\Search The current object * @throws SearchEmptyResultException If there's no results to display * @throws SearchRequiresSphinxException If the search submitted requires Sphinx to run * @throws SearchSphinxOfflineException If the Sphinx server is unreachable * @throws SearchInvalidException If the values of the search weren't compatible with the domain */ protected function p_getSearchComments() { $this->profiler->log('Board::getSearchComments Start'); extract($this->options); // set all empty fields to null $search_fields = ['boards', 'subject', 'text', 'username', 'tripcode', 'email', 'capcode', 'uid', 'poster_ip', 'filename', 'image', 'deleted', 'ghost', 'filter', 'type', 'start', 'end', 'results', 'order']; foreach ($search_fields as $field) { if (!isset($args[$field])) { $args[$field] = null; } } // populate an array containing all boards that would be searched $boards = []; if ($args['boards'] !== null) { foreach ($args['boards'] as $board) { $b = $this->radix_coll->getByShortname($board); if ($b) { $boards[] = $b; } } } // search all boards if none selected if (count($boards) == 0) { $boards = $this->radix_coll->getAll(); } // if image is set, get either the media_hash or media_id if ($args['image'] !== null) { if (substr($args['image'], -2) !== '==') { $args['image'] .= '=='; } // if board is set, retrieve media_id if ($this->radix !== null) { try { $media = $this->media_factory->getByMediaHash($this->radix, $args['image']); } catch (MediaNotFoundException $e) { $this->comments_unsorted = []; $this->comments = []; $this->profiler->log('Board::getSearchComments Ended Prematurely'); throw new SearchEmptyResultException(_i('No results found.')); } $args['image'] = $media->media_id; } } if ($this->radix === null && !$this->preferences->get('foolslide.sphinx.global')) { // global search requires sphinx throw new SearchRequiresSphinxException(_i('Sorry, this action requires the Sphinx to be installed and running.')); } elseif ($this->radix === null && $this->preferences->get('foolslide.sphinx.global') || $this->radix !== null && $this->radix->sphinx) { // configure sphinx connection params $sphinx = explode(':', $this->preferences->get('foolslide.sphinx.listen')); $conn = new SphinxConnnection(); $conn->setParams(['host' => $sphinx[0], 'port' => $sphinx[1], 'options' => [MYSQLI_OPT_CONNECT_TIMEOUT => 5]]); $conn->silenceConnectionWarning(true); // determine if all boards will be used for search or not if ($this->radix == null) { $indexes = []; foreach ($boards as $radix) { if (!$radix->sphinx) { continue; } $indexes[] = $radix->shortname . '_ancient'; $indexes[] = $radix->shortname . '_main'; $indexes[] = $radix->shortname . '_delta'; } } else { $indexes = [$this->radix->shortname . '_ancient', $this->radix->shortname . '_main', $this->radix->shortname . '_delta']; } // establish connection try { $query = SphinxQL::create($conn)->select('id', 'board')->from($indexes); } catch (\Foolz\SphinxQL\ConnectionException $e) { throw new SearchSphinxOfflineException(_i('The search backend is currently unavailable.')); } // parse search params if ($args['subject'] !== null) { $query->match('title', $args['subject']); } if ($args['text'] !== null) { if (mb_strlen($args['text'], 'utf-8') < 1) { return []; } $query->match('comment', $args['text'], true); } if ($args['username'] !== null) { $query->match('name', $args['username']); } if ($args['tripcode'] !== null) { $query->match('trip', '"' . $args['tripcode'] . '"'); } if ($args['email'] !== null) { $query->match('email', $args['email']); } if ($args['capcode'] !== null) { if ($args['capcode'] === 'user') { $query->where('cap', ord('N')); } elseif ($args['capcode'] === 'mod') { $query->where('cap', ord('M')); } elseif ($args['capcode'] === 'admin') { $query->where('cap', ord('A')); } elseif ($args['capcode'] === 'dev') { $query->where('cap', ord('D')); } } if ($args['uid'] !== null) { $query->match('pid', $args['uid']); } if ($this->getAuth()->hasAccess('comment.see_ip') && $args['poster_ip'] !== null) { $query->where('pip', (int) Inet::ptod($args['poster_ip'])); } if ($args['filename'] !== null) { $query->match('media_filename', $args['filename']); } if ($args['image'] !== null) { if ($this->radix !== null) { $query->where('mid', (int) $args['image']); } else { $query->match('media_hash', '"' . $args['image'] . '"'); } } if ($args['deleted'] !== null) { if ($args['deleted'] == 'deleted') { $query->where('is_deleted', 1); } if ($args['deleted'] == 'not-deleted') { $query->where('is_deleted', 0); } } if ($args['ghost'] !== null) { if ($args['ghost'] == 'only') { $query->where('is_internal', 1); } if ($args['ghost'] == 'none') { $query->where('is_internal', 0); } } if ($args['filter'] !== null) { if ($args['filter'] == 'image') { $query->where('has_image', 0); } if ($args['filter'] == 'text') { $query->where('has_image', 1); } } if ($args['type'] !== null) { if ($args['type'] == 'sticky') { $query->where('is_sticky', 1); } if ($args['type'] == 'op') { $query->where('is_op', 1); } if ($args['type'] == 'posts') { $query->where('is_op', 0); } } if ($args['start'] !== null) { $query->where('timestamp', '>=', intval(strtotime($args['start']))); } if ($args['end'] !== null) { $query->where('timestamp', '<=', intval(strtotime($args['end']))); } if ($args['results'] !== null) { if ($args['results'] == 'op') { $query->groupBy('thread_num'); $query->withinGroupOrderBy('is_op', 'desc'); } if ($args['results'] == 'posts') { $query->where('is_op', 0); } } if ($args['order'] !== null && $args['order'] == 'asc') { $query->orderBy('timestamp', 'ASC'); } else { $query->orderBy('timestamp', 'DESC'); } $max_matches = $this->preferences->get('foolslide.sphinx.max_matches', 5000); // set sphinx options $query->limit($limit)->offset($page * $limit - $limit >= $max_matches ? $max_matches - 1 : $page * $limit - $limit)->option('max_matches', (int) $max_matches)->option('reverse_scan', $args['order'] === 'asc' ? 0 : 1); // submit query try { $search = $query->execute(); } catch (\Foolz\SphinxQL\DatabaseException $e) { $this->logger->error('Search Error: ' . $e->getMessage()); throw new SearchInvalidException(_i('The search backend returned an error.')); } // no results found if (!count($search)) { $this->comments_unsorted = []; $this->comments = []; throw new SearchEmptyResultException(_i('No results found.')); } $sphinx_meta = Helper::pairsToAssoc(Helper::create($conn)->showMeta()->execute()); $this->total_count = $sphinx_meta['total']; $this->total_found = $sphinx_meta['total_found']; // populate sql array for full records $sql = []; foreach ($search as $doc => $result) { $board = $this->radix_coll->getById($result['board']); $sql[] = $this->dc->qb()->select('*, ' . $result['board'] . ' AS board_id')->from($board->getTable(), 'r')->leftJoin('r', $board->getTable('_images'), 'mg', 'mg.media_id = r.media_id')->where('doc_id = ' . $this->dc->getConnection()->quote($result['id']))->getSQL(); } $result = $this->dc->getConnection()->executeQuery(implode(' UNION ', $sql))->fetchAll(); } else { // this is not implemented yet, would require some sort of MySQL search throw new SearchRequiresSphinxException(_i('Sorry, this board does not have search enabled.')); } // no results found IN DATABASE, but we might still get a search count from Sphinx if (!count($result)) { $this->comments_unsorted = []; $this->comments = []; } else { // process results foreach ($result as $key => $row) { $board = $this->radix !== null ? $this->radix : $this->radix_coll->getById($row['board_id']); $bulk = new CommentBulk(); $bulk->import($row, $board); $this->comments_unsorted[] = $bulk; unset($result[$key]); } } $this->comments[0]['posts'] = $this->comments_unsorted; return $this; }
public function router($method, $parameters) { $request = $this->getRequest(); // create response object, store request object if ($request->isXmlHttpRequest()) { $this->response = new JsonResponse(); } else { $this->response = new Response(); } $this->request = $request; // let's see if we hit a radix route if ($request->attributes->get('radix_shortname') !== null) { // the radix for sure exists, we came here from the defined routes after all $this->radix = $this->radix_coll->getByShortname($request->attributes->get('radix_shortname')); $this->param_manager->setParam('radix', $this->radix); $backend_vars = $this->param_manager->getParam('backend_vars'); $backend_vars['board_shortname'] = $this->radix->shortname; $this->param_manager->setParam('backend_vars', $backend_vars); $this->builder->getProps()->addTitle($this->radix->getValue('formatted_title')); // methods callable with a radix are prefixed with radix_ if (method_exists($this, 'radix_' . $method)) { return [$this, 'radix_' . $method, $parameters]; } // a board and no function means we're out of the street return [$this, 'action_404', []]; } $this->radix = null; $this->param_manager->setParam('radix', null); $this->builder->getProps()->addTitle($this->preferences->get('foolframe.gen.website_title', $this->preferences->get('foolslide.gen.website_title'))); if (method_exists($this, 'action_' . $method)) { return [$this, 'action_' . $method, $parameters]; } return [$this, 'action_404', []]; }