示例#1
0
 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)');
         }
     }
 }
示例#2
0
 /**
  * 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.';
         }
     }
 }
示例#3
0
 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;
 }
示例#4
0
 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];
             }
         }
     }
 }
示例#5
0
 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();
 }
示例#6
0
文件: User.php 项目: block8/octo
 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;
 }
示例#7
0
 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);
 }
示例#8
0
 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;
 }
示例#9
0
 protected function loadDashboardStatistics()
 {
     $stats = [];
     Event::trigger('DashboardStatistics', $stats);
     $this->template->statistics = $stats;
 }
示例#10
0
文件: Member.php 项目: block8/octo
 public function login(Contact $contact)
 {
     $_SESSION[self::getSessionKey()] = $contact->getId();
     $this->active = $contact;
     Event::trigger('memberLogin', $member);
 }
示例#11
0
 /**
  * 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');
 }
示例#12
0
 public function render()
 {
     $code = parent::render();
     Event::trigger('OnTemplateRender', $code);
     return $code;
 }
示例#13
0
 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;
 }
示例#15
0
 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;
 }
示例#16
0
 /**
  * @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;
 }
示例#17
0
文件: Response.php 项目: block8/octo
 public function flush()
 {
     Event::trigger('Response.Flush', $this);
     return parent::flush();
 }
示例#18
0
 /**
  * Every controller requires an init function
  */
 public function init()
 {
     Event::trigger('Controller.Loaded', $this);
     Event::trigger('Controller.Loaded.Admin', $this);
 }
示例#19
0
文件: Template.php 项目: block8/octo
 public function render()
 {
     $output = $this->template->render($this->variables);
     Event::trigger('OnTemplateRender', $output);
     return $output;
 }