Пример #1
0
 public function init()
 {
     $this->setTitle('Users');
     $this->addBreadcrumb('Users', '/user');
     $this->userStore = Store::get('User');
     $this->permissionStore = Store::get('Permission');
 }
Пример #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
 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)');
         }
     }
 }
Пример #4
0
 protected function updateUploads($scope)
 {
     $logStore = Store::get('Log');
     $fileStore = Store::get('File');
     $last = $logStore->getLastEntry($scope);
     $date = new \DateTime('-1 day');
     if (!is_null($last)) {
         $date = $last->getLogDate();
     }
     $items = $fileStore->getAllForScopeSince($scope, $date);
     $itemCount = 0;
     $message = [];
     $user = null;
     foreach ($items as $item) {
         if (++$itemCount > 3) {
             break;
         }
         if (empty($user)) {
             $user = $item->getUser();
         }
         $message[] = ['title' => $item->getTitle(), 'id' => $item->getId()];
     }
     if (count($message)) {
         $log = Log::create(Log::TYPE_CREATE, $scope, json_encode($message));
         $log->setUser($user);
         $log->save();
     }
 }
Пример #5
0
 /**
  * Get tweets for the currently authenticated twitter user
  */
 public static function getUser()
 {
     $tweetStore = Store::get('Tweet');
     $consumerKey = Setting::get('twitter', 'consumer_key');
     $consumerSecret = Setting::get('twitter', 'consumer_secret');
     $accessToken = Setting::get('twitter', 'access_token');
     $accessTokenSecret = Setting::get('twitter', 'access_token_secret');
     $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
     if (self::canCallAPI()) {
         self::updateLastAPICall();
         $statuses = $twitter->load(Twitter::ME);
         foreach ($statuses as $s) {
             if (!$tweetStore->getByTwitterIdForScope($s->id, 'user')) {
                 $t = new Tweet();
                 $t->setTwitterId($s->id);
                 $t->setText($s->text);
                 $t->setHtmlText(Twitter::clickable($s));
                 $t->setScreenname($s->user->screen_name);
                 $t->setPosted($s->created_at);
                 $t->setCreatedDate(new \DateTime());
                 $t->setScope('user');
                 $tweetStore->saveByInsert($t);
             }
         }
     }
 }
Пример #6
0
 public function run()
 {
     /** @var \Octo\System\Store\JobStore $jobStore */
     $jobStore = Store::get('Job');
     /** @var \Octo\System\Store\ScheduledJobStore $scheduleStore */
     $scheduleStore = Store::get('ScheduledJob');
     // Clean up existing Scheduler jobs from the database:
     $jobs = $jobStore->getByType('Octo.System.Scheduler');
     foreach ($jobs as $job) {
         if ($job->getId() != $this->job->getId()) {
             Manager::delete($job);
         }
     }
     // Create the next Scheduler job:
     Manager::create($this->job, Job::PRIORITY_HIGH, 5);
     // Schedule other jobs:
     $jobs = $scheduleStore->getJobsToSchedule();
     foreach ($jobs as $item) {
         $job = new Job();
         $job->setType($item->getType());
         $data = json_decode($item->getData(), true);
         if (!empty($data) && is_array($data)) {
             $job->setData($data);
         }
         $job = Manager::create($job);
         $item->setCurrentJob($job);
         $scheduleStore->save($item);
     }
     return true;
 }
Пример #7
0
 public function addToSearchIndex(&$data)
 {
     $this->searchStore = Store::get('SearchIndex');
     $class = get_class($data['model']);
     $class = explode('\\', $class);
     $class = end($class);
     $this->searchStore->updateSearchIndex($class, $data['content_id'], $data['content']);
     return true;
 }
Пример #8
0
 public function getWidget(&$widgets)
 {
     // Recently active users:
     /** @var \Octo\System\Store\UserStore $store */
     $store = Store::get('User');
     $view = new Template('Dashboard/recent-users', 'admin');
     $view->users = $store->getRecentUsers();
     $widgets[] = ['order' => 1, 'html' => $view->render()];
 }
Пример #9
0
 public function getStatistics(&$stats)
 {
     /** @var \Octo\System\Model\User $user */
     $user = $_SESSION['user'];
     if ($user->canAccess('/contact')) {
         $contactStore = Store::get('Contact');
         $total = $contactStore->getTotal();
         $stats[] = ['title' => $total == 1 ? 'Contact' : 'Contacts', 'count' => number_format($total), 'icon' => 'person-stalker', 'color' => 'aqua', 'link' => '/contact', 'link_title' => 'View Contacts'];
     }
 }
Пример #10
0
 public function init()
 {
     $this->store = Store::get('Contact');
     if (!empty($_SESSION[$this->getSessionKey()])) {
         $member = $this->store->getById($_SESSION[$this->getSessionKey()]);
         if (!empty($member)) {
             $this->active = $member;
         }
     }
 }
Пример #11
0
 public static function getAllAsArray()
 {
     /** @var \Octo\System\Store\SettingStore $settingStore */
     $settingStore = Store::get('Setting');
     $settings = $settingStore->all();
     $rtn = [];
     foreach ($settings as $setting) {
         $rtn[$setting->getScope() . '_' . $setting->getKey()] = $setting->getValue();
     }
     return $rtn;
 }
Пример #12
0
 public function index()
 {
     $this->searchStore = Store::get('SearchIndex');
     $query = $this->getParam('q', '');
     $this->setTitle($query, 'Search ' . $this->config->get('site.name'));
     $this->addBreadcrumb('Search', '/search?q=' . $query);
     $results = $this->searchStore->search($query);
     $results = array_map([$this, 'render'], $results);
     $this->view->query = $query;
     $this->view->results = $results;
 }
Пример #13
0
 public function autocomplete()
 {
     $contacts = Store::get('Contact')->search($this->getParam('q', ''));
     $rtn = ['results' => [], 'more' => false];
     foreach ($contacts as $contact) {
         $name = $contact->getFirstName() . ' ' . $contact->getLastName();
         if ($contact->getCompany()) {
             $name .= ' (' . $contact->getCompany() . ')';
         }
         $rtn['results'][] = ['id' => $contact->getId(), 'text' => $name];
     }
     die(json_encode($rtn));
 }
Пример #14
0
 public function run()
 {
     $this->store = Store::get('SystemJob');
     $job = $this->store->getNextJob();
     if (!is_null($job)) {
         $runDate = $job->getRunDate();
         $runDate->add(new \DateInterval($job->getFrequency()));
         $job->setRunDate($runDate);
         $this->store->save($job);
         chdir(APP_PATH);
         exec('nohup /usr/bin/php vendor/bin/octocmd ' . $job->getCommand() . ' >/dev/null 2>/dev/null &');
     }
     die('OK');
 }
Пример #15
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];
             }
         }
     }
 }
Пример #16
0
 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;
 }
Пример #17
0
 public function resetPassword($memberId)
 {
     $view = new Template('Member/forgot-password');
     $member = Store::get('Contact')->getById($memberId);
     $key = $this->getParam('k', null);
     if (is_null($member) || $key != $this->getResetKey($member)) {
         $this->response->setResponseCode(401);
         $view->errorMessage = 'Invalid password reset request.';
         return $view->render();
     }
     $view->text = '<strong>Please enter a new password below.</strong><br><br>';
     $view->form = $this->resetPasswordForm($memberId, $key);
     if ($this->request->getMethod() == 'POST') {
         $member->setPasswordHash(password_hash($this->getParam('password'), PASSWORD_DEFAULT));
         Store::get('Contact')->save($member);
         Member::getInstance()->login($member);
         $this->response->setResponseCode(302);
         $this->response->setHeader('Location', $this->config->get('site.url'));
         return;
     }
     return $view->render();
 }
Пример #18
0
 public function search($string)
 {
     $database = Database::getConnection('read');
     $words = $this->extractWords($string);
     $words = '\'' . implode('\', \'', array_keys($words)) . '\'';
     $query = 'SELECT model, content_id
                 FROM search_index
                 WHERE word IN (' . $words . ')
                 GROUP BY model, content_id
                 ORDER BY SUM(instances) DESC LIMIT 20;';
     $stmt = $database->prepare($query);
     $rtn = [];
     if ($stmt->execute()) {
         $res = $stmt->fetchAll(Database::FETCH_ASSOC);
         foreach ($res as $item) {
             $store = StoreFactory::get($item['model']);
             if ($store) {
                 $rtn[] = $store->getByPrimaryKey($item['content_id']);
             }
         }
     }
     return $rtn;
 }
 public function auth()
 {
     $email = $this->getParam('email', '');
     $token = $this->getParam('token', '');
     $client = new \Google_Client();
     $client->setClientId(Setting::get('google-identity', 'client_id'));
     $client->setClientSecret(Setting::get('google-identity', 'client_secret'));
     $client->setRedirectUri($this->config->get('site.full_admin_url') . '/google-identity/auth');
     $client->setScopes('email');
     $data = $client->verifyIdToken($token)->getAttributes();
     if (empty($data['payload']['email']) || $data['payload']['email'] != $email) {
         return $this->redirect('/session/login?logout=1')->error('There was a problem signing you in, please try again.');
     }
     $userStore = Store::get('User');
     $user = $userStore->getByEmail($email);
     if (is_null($user)) {
         $authDomains = Setting::get('google-identity', 'login_auto_create');
         $authDomains = explode(',', $authDomains);
         $parts = explode('@', $email, 2);
         if (!in_array($parts[1], $authDomains)) {
             return $this->redirect('/session/login?logout=1')->error('You do not have permission to sign in.');
         }
         $user = new User();
         $user->setActive(1);
         $user->setIsAdmin(1);
         $user->setDateAdded(new \DateTime());
         $user->setEmail($email);
         $user->setName($data['payload']['name']);
         $user = $userStore->save($user);
     }
     $_SESSION['user_id'] = $user->getId();
     if (isset($_SESSION['previous_url'])) {
         return $this->redirect($_SESSION['previous_url']);
     }
     return $this->redirect('/');
 }
Пример #20
0
 protected function loadTimeline()
 {
     $logStore = Store::get('Log');
     $items = $logStore->getTimeline();
     $timeline = [];
     $lastDate = new \DateTime('1970-01-01');
     foreach ($items as $item) {
         if ($item->getLogDate()->format('Y-m-d') != $lastDate->format('Y-m-d')) {
             $date = $item->getLogDate()->format('M j Y');
             $timeline[] = "<li class=\"time-label\">\n                                    <span class=\"bg-blue\">\n                                        {$date}\n                                    </span>\n                                </li>";
             $lastDate = $item->getLogDate();
         }
         $keyDate = $item->getLogDate()->format('Y-m-d');
         $key = md5($keyDate . $item->getScope() . '.' . $item->getType() . '.' . $item->getScopeId());
         if (array_key_exists($key, $timeline)) {
             continue;
         }
         $template = 'Dashboard/Timeline/' . $item->getScope();
         if (!Template::exists($template)) {
             $template = 'Dashboard/Timeline/default';
         }
         $template = Template::getAdminTemplate($template);
         $template->icon = 'info';
         $template->item = $item;
         $template->decoded = @json_decode($item->getMessage(), true);
         switch ($item->getType()) {
             case 2:
                 $template->color = 'green';
                 $template->verb = 'created';
                 break;
             case 4:
                 $template->color = 'red';
                 $template->verb = 'deleted';
                 break;
             case 8:
                 $template->color = 'blue';
                 $template->verb = 'edited';
                 break;
             case 128:
                 $template->color = 'blue';
                 $template->verb = 'published';
                 break;
         }
         switch ($item->getScope()) {
             case 'user':
                 $template->icon = 'user';
                 break;
             case 'page':
                 $template->icon = 'file-text';
                 break;
             case 'file':
                 $template->icon = 'image';
                 break;
             case 'info':
                 $template->icon = 'user';
                 break;
         }
         $timeline[$key] = $template->render();
         if (count($timeline) >= 20) {
             break;
         }
     }
     return $timeline;
 }
Пример #21
0
$moduleManager->setConfig($config);
$moduleManager->enable('Octo', 'System');
// Set up config:
if (is_file(APP_PATH . 'siteconfig.php')) {
    require_once APP_PATH . 'siteconfig.php';
}
$_SETTINGS['site']['full_admin_url'] = $_SETTINGS['site']['url'] . '/' . $_SETTINGS['site']['admin_uri'];
$_SETTINGS['Octo']['AssetManager'] = new \Octo\AssetManager();
$config->setArray($_SETTINGS);
$moduleManager->initialiseModules();
$host = $config->get('b8.database.servers.write');
$user = $config->get('b8.database.username');
$pass = $config->get('b8.database.password');
$name = $config->get('b8.database.name');
\Block8\Database\Connection::setConfig($host, $user, $pass, $name);
\Octo\Store::setNamespaces($config->get('app.namespaces'));
$templatePath = realpath(APP_PATH . $_SETTINGS['site']['namespace'] . '/Template');
define('SITE_TEMPLATE_PATH', $templatePath);
if (is_dir($templatePath)) {
    $settings = $config->get('Octo');
    $settings['paths']['templates'][] = $templatePath . '/';
    $config->set('Octo', $settings);
}
//set up ADMIN_URI constant, throws exception if the config value isn't set.
if (!defined('ADMIN_URI')) {
    if ($config->get('site.admin_uri') === null) {
        throw new Exception('site.admin_uri has not been set in the siteconfig');
    } else {
        define('ADMIN_URI', $config->get('site.admin_uri'));
    }
}
Пример #22
0
 public function init()
 {
     $this->contactStore = Store::get('Contact');
 }
Пример #23
0
 public function ScheduledJobs()
 {
     return Store::get('ScheduledJob')->where('current_job_id', $this->data['id']);
 }
Пример #24
0
 public function Permissions()
 {
     return Store::get('Permission')->where('user_id', $this->data['id']);
 }
Пример #25
0
 public function init()
 {
     $this->searchStore = Store::get('SearchIndex');
 }
Пример #26
0
 /**
  * Get the User model for this  by Id.
  *
  * @uses \Octo\System\Store\UserStore::getById()
  * @uses \Octo\System\Model\User
  * @return \Octo\System\Model\User
  */
 public function getUser()
 {
     $key = $this->getUserId();
     if (empty($key)) {
         return null;
     }
     return Store::get('User')->getById($key);
 }
Пример #27
0
 public function __construct()
 {
     $this->searchStore = Store::get('SearchIndex');
 }
Пример #28
0
 public function save()
 {
     Store::get('Log')->save($this);
 }
Пример #29
0
 /**
  * @return JobStore
  */
 protected static function getStore()
 {
     return Store::get('Job');
 }
Пример #30
0
 public function PageVersions()
 {
     return Store::get('PageVersion')->where('content_item_id', $this->data['id']);
 }