protected function execute(InputInterface $input, OutputInterface $output) { unset($input); $items = glob(CMS_PATH . '*/Model/*.php'); foreach ($items as $item) { $model = str_replace([CMS_BASE_PATH, '/', '.php'], ['', '\\', ''], $item); $systemModels[] = $model; } foreach (glob(APP_PATH . "*", GLOB_ONLYDIR) as $path) { $items = glob($path . '/*/Model/*.php'); foreach ($items as $item) { $model = str_replace([APP_PATH, '/', '.php'], ['', '\\', ''], $item); $systemModels[] = $model; } } foreach ($systemModels as $model) { $myModel = new $model(); if (method_exists($myModel, 'getIndexableContent')) { $reflect = new \ReflectionClass($myModel); $myStore = Store::get($reflect->getShortName()); $modelsToIndex = $myStore->getModelsToIndex(); $output->write('Indexing: ' . $reflect->getShortName()); $count = 0; foreach ($modelsToIndex as $newModel) { $count++; $content = $newModel->getIndexableContent(); $data = ['model' => $newModel, 'content_id' => $newModel->getId(), 'content' => $content]; Event::trigger('ContentPublished', $data); } $output->writeln(' (' . $count . ' items)'); } } }
/** * Handles user login (form and processing) */ public function login() { if (file_exists(APP_PATH . 'public/assets/images/cms-logo.png')) { $this->view->siteLogo = true; } $_SESSION['auth'] = 'login'; $this->view->emailFieldLabel = 'Email Address'; $this->userStoreName = 'User'; $this->userGetMethod = 'getByEmail'; Event::trigger('beforeLogin', $this); if ($this->request->getMethod() == 'POST') { $ugMethod = $this->userGetMethod; $user = Store::get($this->userStoreName)->{$ugMethod}($this->getParam('email')); if ($user && password_verify($this->getParam('password', ''), $user->getHash())) { $_SESSION['user_id'] = $user->getId(); $url = $this->config->get('site.full_admin_url'); if (isset($_SESSION['previous_url'])) { $url = $_SESSION['previous_url']; } header('Location: ' . $url); die; } else { Event::trigger('loginFailed', $this->view); $label = strtolower($this->view->emailFieldLabel); $this->view->errorMessage = 'Your ' . $label . ' or password were wrong.'; } } }
public function index() { $query = $this->getParam('q', ''); $results = $this->searchStore->search($query); $results = array_map([$this, 'render'], $results); $view = Template::load('Search/results'); $view->query = $query; $view->results = $results; $dataStore = ['breadcrumb' => [['uri' => '/', 'title' => 'Home', 'active' => false], ['uri' => '/search', 'title' => 'Search', 'active' => false], ['uri' => '/search?q=' . $query, 'title' => $query, 'active' => true]]]; $blockManager = new BlockManager(); $blockManager->setDataStore($dataStore); $blockManager->setRequest($this->request); $blockManager->setResponse($this->response); $blockManager->attachToTemplate($view); $output = $view->render(); $data = ['page' => null, 'version' => null, 'output' => &$output, 'datastore' => $blockManager->getDataStore()]; Event::trigger('PageLoaded', $data); return $output; }
public function init() { parent::init(); $this->setTitle('Jobs'); $this->addBreadcrumb('Jobs', '/job'); $this->jobStore = Store::get('Job'); $this->scheduleStore = Store::get('ScheduledJob'); // Get job handlers: $registeredHandlers = []; Event::trigger('RegisterJobHandlers', $registeredHandlers); $this->handlers = []; foreach ($registeredHandlers as $handler) { $func = [$handler, 'getJobTypes']; if (class_exists($handler) && method_exists($handler, 'getJobTypes')) { foreach (call_user_func($func) as $jobType => $jobName) { $this->handlers[$jobType] = ['name' => $jobName, 'handler' => $handler]; } } } }
public function login() { $view = new Template('Member/login'); $view->form = Member::getInstance()->getLoginForm($this->getParam('rtn', '/')); Event::trigger('beforeMemberLogin', $this); if ($this->request->getMethod() == 'POST') { $member = Store::get('Contact')->getByEmail($this->getParam('email')); if ($member && password_verify($this->getParam('password', ''), $member->getPasswordHash())) { Member::getInstance()->login($member); $this->response->setResponseCode(302); $this->response->setHeader('Location', $this->getParam('rtn', '/')); return $this->response; } else { Event::trigger('memberLoginFailed', $view); $message = 'Your email address or password were incorrect.'; $view->errorMessage = $message; } } return $view->render(); }
public function canAccess($uri) { $canAccess = null; $callbackData = [$this, $uri, $canAccess]; Event::trigger('canAccess', $callbackData); $uri = $callbackData[1]; $canAccess = $callbackData[2]; if (!is_null($canAccess)) { return $canAccess; } if ($this->getIsAdmin()) { return true; } if (!isset($this->permissionsArray)) { $this->permissionsArray = Store::get('Permission')->getPermissionsArray($this); } if (array_key_exists($uri, $this->permissionsArray) && $this->permissionsArray[$uri]) { return true; } return false; }
public function initHttpRequest() { Event::trigger('BeforeHttpRequestInit', $this); $path = $this->request->getPath(); if (substr($path, -1) == '/' && $path != '/') { header('HTTP/1.1 302 Moved Permanently', true, 301); header('Location: ' . $this->config->get('site.url') . substr($path, 0, -1)); die; } $this->router->clearRoutes(); Event::trigger('BackupRoutes', $this->router); $this->router->register('/:controller/:action', ['namespace' => 'Controller', 'action' => 'index']); $route = '/' . $this->config->get('site.admin_uri') . '/:controller/:action'; $defaults = ['namespace' => 'Admin\\Controller', 'controller' => 'Dashboard', 'action' => 'index']; $request =& $this->request; Event::trigger('PrimaryRoutes', $this->router); $denied = [$this, 'permissionDenied']; $rtn = $this->registerRouter($route, $defaults, $request, $denied); $this->router->register('/robots.txt', ['controller' => 'Page'], function (&$route, Response &$response) { header('Content-Type: text/plain'); die('User-Agent: *' . PHP_EOL . 'Disallow: /manage/' . PHP_EOL . 'Allow: /'); }); Event::trigger('AfterHttpRequestInit', $this); }
public function edit($contactId) { $contact = $this->contactStore->getById($contactId); $this->setTitle('Edit Contact', 'Contacts'); if ($this->request->getMethod() == 'POST') { $contact->setValues($this->getParams()); $contact = $this->contactStore->save($contact); $data = ['model' => $contact, 'content_id' => $contact->getId(), 'content' => $contact->getFirstName() . ' ' . $contact->getLastName() . ' ' . $contact->getCompany()]; Event::trigger('ContentPublished', $data); $this->redirect('/contact/edit/' . $contact->getId()); } $form = $this->contactForm(); $form->setValues($contact->getDataArray()); $this->view->form = $form; }
protected function loadDashboardStatistics() { $stats = []; Event::trigger('DashboardStatistics', $stats); $this->template->statistics = $stats; }
public function login(Contact $contact) { $_SESSION[self::getSessionKey()] = $contact->getId(); $this->active = $contact; Event::trigger('memberLogin', $member); }
/** * b8 framework requires that controllers have an init() method */ public function init() { Event::trigger('Controller.Loaded', $this); Event::trigger('Controller.Loaded.Public', $this); $this->assets = Config::getInstance()->get('Octo.AssetManager'); }
public function render() { $code = parent::render(); Event::trigger('OnTemplateRender', $code); return $code; }
protected function userForm($values, $type = 'add') { $form = new FormElement(); $form->setMethod('POST'); if ($type == 'add') { $form->setAction($this->config->get('site.full_admin_url') . '/user/add'); } else { $form->setAction($this->config->get('site.full_admin_url') . '/user/edit/' . $values['id']); } $form->setClass('smart-form'); $fieldset = new Form\FieldSet('fieldset'); $form->addField($fieldset); if (isset($values['id'])) { $field = new Form\Element\Hidden('id'); $field->setRequired(true); $field->setValue($values['id']); $fieldset->addField($field); } $field = new Form\Element\Text('name'); $field->setRequired(true); $field->setLabel('Name'); $fieldset->addField($field); $field = new Form\Element\Email('email'); $field->setRequired(true); $field->setLabel('Email Address'); $fieldset->addField($field); $field = new Form\Element\Password('password'); if ($type == 'add') { $field->setRequired(true); } else { $field->setRequired(false); } $field->setLabel('Password' . ($type == 'edit' ? ' (leave blank to keep current password)' : '')); $fieldset->addField($field); if ($this->currentUser->getIsAdmin()) { $field = new Form\Element\Select('is_admin'); $field->setRequired(false); $field->setLabel('Administrator'); $field->setOptions([0 => 'No', 1 => 'Yes']); $fieldset->addField($field); } $data = [&$form, &$values]; Event::trigger('userForm', $data); list($form, $values) = $data; $fieldset = new Form\FieldSet('fieldset3'); $form->addField($fieldset); $field = new Form\Element\Submit(); $field->setValue('Save User'); $field->setClass('btn-success'); $fieldset->addField($field); $form->setValues($values); return $form; }
public function settings() { $this->setTitle('Google Identity'); $values = Setting::getForScope('google-identity'); $form = $this->settingsForm($values); if ($this->request->getMethod() == 'POST') { $params = $this->getParams(); $form->setValues($params); Setting::setForScope('google-identity', $form->getValues()); $this->successMessage('Settings saved successfully.'); } else { $form->setValues($values); } $scopes = []; Event::trigger('Octo.GoogleIdentity.GetScopes', $scopes); $this->template->scopes = implode(' ', array_unique($scopes)); $this->template->form = $form; }
public function render() { $parts = explode('\\', get_class($this)); $class = array_pop($parts); try { $this->view = new Template('Block/' . $class); } catch (\Exception $ex) { $this->view = null; } $rtn = $this->renderNow(); if (method_exists($this, 'renderDeferred')) { $manager = Event::getEventManager(); $manager->registerListener('PageLoaded', [$this, 'renderDeferred']); } if ($rtn === false) { return ''; } if (!is_null($rtn)) { return $rtn; } return $this->view; }
/** * @return array */ protected function setupHandlers() { // Get handlers: $handlers = []; Event::trigger('RegisterJobHandlers', $handlers); $rtn = []; foreach ($handlers as $handler) { $func = [$handler, 'getJobTypes']; if (class_exists($handler) && method_exists($handler, 'getJobTypes')) { foreach (call_user_func($func) as $jobType => $jobName) { $rtn[$jobType] = ['name' => $jobName, 'handler' => $handler]; } } } return $rtn; }
public function flush() { Event::trigger('Response.Flush', $this); return parent::flush(); }
/** * Every controller requires an init function */ public function init() { Event::trigger('Controller.Loaded', $this); Event::trigger('Controller.Loaded.Admin', $this); }
public function render() { $output = $this->template->render($this->variables); Event::trigger('OnTemplateRender', $output); return $output; }