/** * @return array */ public function getPermissions() { if (!$this->perms) { foreach (App::module() as $module) { if ($perms = $module->get('permissions')) { $this->registerPermissions($module->get('name'), $perms); } } App::trigger('user.permission', [$this]); } return $this->perms; }
/** * @return array */ public function getTypes() { if (!$this->types) { foreach (App::module() as $module) { foreach ((array) $module->get('nodes') as $type => $route) { $this->registerType($type, $route); } } $this->registerType('link', ['label' => 'Link', 'frontpage' => false]); App::trigger('site.types', [$this]); } return $this->types; }
/** * @param $packages */ public function enable($packages) { if (!is_array($packages)) { $packages = [$packages]; } foreach ($packages as $package) { App::trigger('package.enable', [$package]); if (!($current = App::config('system')->get('packages.' . $package->get('module')))) { $current = $this->doInstall($package); } $scripts = $this->getScripts($package, $current); if ($scripts->hasUpdates()) { $scripts->update(); } $version = $this->getVersion($package); App::config('system')->set('packages.' . $package->get('module'), $version); $scripts->enable(); if ($package->getType() == 'pagekit-theme') { App::config('system')->set('site.theme', $package->get('module')); } elseif ($package->getType() == 'pagekit-extension') { App::config('system')->push('extensions', $package->get('module')); } } }
protected function getMode($path) { $mode = App::trigger(new FileAccessEvent('system.finder'))->mode($path); if ('w' == $mode && !is_writable($path)) { $mode = 'r'; } if ('r' == $mode && !is_readable($path)) { $mode = '-'; } return $mode; }
/** * @Route("/{id}", name="id") * @Request({"id":"int", "category_id":"int"}) */ public function fileAction($id = 0, $category_id = 0) { /** @var File $file */ if (!($file = File::where(['id = ?', 'status = ?'], [$id, '1'])->where(function ($query) { return $query->where('roles IS NULL')->whereInSet('roles', App::user()->roles, false, 'OR'); })->first())) { App::abort(404, __('File not found.')); } $file->setActiveCategory($category_id); App::trigger('bixie.prepare.file', [$file, App::view()]); $file->content = App::content()->applyPlugins($file->content, ['file' => $file, 'markdown' => $file->get('markdown')]); $previous = File::getPrevious($file); $next = File::getNext($file); /** @var Category $category */ if ($category_id && !($category = Category::where(['id = ?', 'status = ?'], [$category_id, '1'])->where(function ($query) { return $query->where('roles IS NULL')->whereInSet('roles', App::user()->roles, false, 'OR'); })->related('files')->first())) { App::abort(404, __('Category not found.')); } if ($breadcrumbs = App::module('bixie/breadcrumbs')) { if ($category_id) { $cat = $category; $crumbs = [['title' => $category->title, 'url' => $category->getUrl()]]; while ($parent_id = $cat->parent_id) { if ($cat = $cat->find($parent_id, true)) { $crumbs[] = ['title' => $cat->title, 'url' => $cat->getUrl()]; } } foreach (array_reverse($crumbs) as $data) { $breadcrumbs->addUrl($data); } } //add file $breadcrumbs->addUrl(['title' => $file->title, 'url' => $file->getUrl()]); } return ['$view' => ['title' => __($file->title), 'name' => 'bixie/download/file.php'], 'download' => $this->download, 'config' => $this->download->config(), 'previous' => $previous, 'next' => $next, 'file' => $file, 'node' => App::node()]; }
/** * Applies content plugins * * @param string $content * @param array $parameters * @return mixed */ public function applyPlugins($content, $parameters = []) { return App::trigger(new ContentEvent('content.plugins', $content, $parameters))->getContent(); }
/** * @Route("/", methods="POST") * @Route("/{id}", methods="POST", requirements={"id"="\d+"}) * @Request({"submission": "array", "id": "int", "g-recaptcha-response": "string"}, csrf=true) */ public function saveAction($data, $id = 0, $gRecaptchaResponse = '') { if (!($submission = Submission::find($id))) { $submission = Submission::create(); unset($data['id']); $submission->form_id = $data['form_id']; $submission->created = new \DateTime(); $submission->ip = App::request()->getClientIp(); } unset($data['created']); if (!($form = Form::find($submission->form_id))) { App::abort(404, 'Form not found.'); } $submission->form = $form; if ($form->get('recaptcha') and $id == 0 and $recaptha_secret_key = App::module('bixie/formmaker')->config('recaptha_secret_key')) { $resp = (new ReCaptcha($recaptha_secret_key))->verify($gRecaptchaResponse, App::request()->server->get('REMOTE_ADDR')); if (!$resp->isSuccess()) { $errors = $resp->getErrorCodes(); App::abort(403, isset($errors[0]) ? $errors[0] : 'Error in reCaptcha'); } } $submission->save($data); $submission->email = $submission->getUserEmail(); if ($id == 0) { App::trigger('formmaker.form.submission', [$form, $submission]); try { (new MailHelper($submission))->sendMail(); $submission->save(); } catch (Exception $e) { App::abort(400, $e->getMessage()); } } return ['message' => 'Submission successful', 'submission' => $submission]; }