示例#1
0
 public function before()
 {
     $request = $this->getRequest();
     $this->uri = $this->getContext()->getService('uri');
     $this->mailer = $this->getContext()->getService('mailer');
     $this->notices = $this->getContext()->getService('notices');
     $this->preferences = $this->getContext()->getService('preferences');
     $this->config = $this->getContext()->getService('config');
     $this->security = $this->getContext()->getService('security');
     $theme_instance = \Foolz\Theme\Loader::forge('foolframe_admin');
     $theme_instance->addDir(VENDPATH . 'foolz/foolframe/assets/themes-admin/');
     $theme_instance->addDir(VAPPPATH . 'foolz/foolframe/themes-admin/');
     $theme_instance->setBaseUrl($this->uri->base() . 'foolframe/');
     $theme_instance->setPublicDir(DOCROOT . 'foolframe/');
     // make it possible to override the theme so other framework components can extend with their own
     $this->setupTheme($theme_instance);
     $this->builder = $this->theme->createBuilder();
     $this->param_manager = $this->builder->getParamManager();
     $this->builder->createLayout('base');
     $this->builder->getProps()->addTitle(_i('Control Panel') . ' - ' . $this->preferences->get('foolframe.gen.website_title'));
     $this->param_manager->setParams(['context' => $this->getContext(), 'notices' => $this->notices, 'uri' => $this->uri, 'request' => $request]);
     // returns the hardcoded sidebar array (can't use functions when declaring a class variable)
     $sidebar = $this->getSidebarValues();
     $sidebar_dynamic = Hook::forge('Foolz\\FoolFrame\\Controller\\Admin::before#var.sidebar')->setObject($this)->setParam('sidebar', [])->execute()->getParam('sidebar');
     // merge if there were sidebar elements added dynamically
     if (!empty($sidebar_dynamic)) {
         $sidebar = $this->mergeSidebars($sidebar, $sidebar_dynamic);
     }
     $this->builder->createPartial('navbar', 'navbar');
     $this->builder->createPartial('sidebar', 'sidebar')->getParamManager()->setParams(['sidebar' => $this->getSidebar($request, $sidebar)]);
 }
示例#2
0
 public function action_complete()
 {
     $this->process('complete');
     $this->param_manager->setParam('method_title', _i('Congratulations'));
     $this->builder->createPartial('body', 'install/complete');
     return new Response($this->builder->build());
 }
示例#3
0
 public function before()
 {
     $this->config = $this->getContext()->getService('config');
     $this->preferences = $this->getContext()->getService('preferences');
     $this->uri = $this->getContext()->getService('uri');
     $this->profiler = $this->getContext()->getService('profiler');
     // this has already been forged in the foolslide bootstrap
     $theme_instance = \Foolz\Theme\Loader::forge('foolslide');
     try {
         $theme_name = $this->getQuery('theme', $this->getCookie('theme')) ?: $this->preferences->get('foolslide.theme.default');
         $theme_name_exploded = explode('/', $theme_name);
         if (count($theme_name_exploded) >= 2) {
             $theme_name = $theme_name_exploded[0] . '/' . $theme_name_exploded[1];
         }
         $theme = $theme_instance->get($theme_name);
         if (!isset($theme->enabled) || !$theme->enabled) {
             throw new \OutOfBoundsException();
         }
         $this->theme = $theme;
     } catch (\OutOfBoundsException $e) {
         $theme_name = 'foolz/foolslide-theme-foolslide';
         $this->theme = $theme_instance->get('foolz/foolslide-theme-foolslide');
     }
     // TODO this is currently bootstrapped in the foolslide bootstrap because we need it running before the router.
     //$this->theme->bootstrap();
     $this->builder = $this->theme->createBuilder();
     $this->param_manager = $this->builder->getParamManager();
     $this->builder->createLayout('chan');
     if (count($theme_name_exploded) == 3) {
         try {
             $this->builder->setStyle($theme_name_exploded[2]);
         } catch (\OutOfBoundsException $e) {
             // just let it go with default on getStyle()
         }
     }
     // KEEP THIS IN SYNC WITH THE ONE IN THE POSTS ADMIN PANEL
     $to_bind = ['context' => $this->getContext(), 'request' => $this->getRequest(), 'order' => false, 'modifiers' => [], 'backend_vars' => ['site_url' => $this->uri->base(), 'default_url' => $this->uri->base(), 'archive_url' => $this->uri->base(), 'system_url' => $this->uri->base(), 'api_url' => $this->uri->base(), 'cookie_domain' => $this->config->get('foolz/foolframe', 'config', 'config.cookie_domain'), 'cookie_prefix' => $this->config->get('foolz/foolframe', 'config', 'config.cookie_prefix'), 'selected_theme' => $theme_name, 'csrf_token_key' => 'csrf_token', 'images' => [], 'gettext' => ['submit_state' => _i('Submitting'), 'thread_is_real_time' => _i('This thread is being displayed in real time.'), 'update_now' => _i('Update now'), 'ghost_mode' => _i('This thread has entered ghost mode. Your reply will be marked as a ghost post and will only affect the ghost index.')]]];
     $this->param_manager->setParams($to_bind);
     // $this->builder->createPartial('tools_modal', 'tools_modal');
     // $this->builder->createPartial('tools_search', 'tools_search');
     // $this->builder->createPartial('tools_advanced_search', 'advanced_search');
 }
示例#4
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;
 }