コード例 #1
0
ファイル: UserController.php プロジェクト: dw250100785/Octo
 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
ファイル: BuildSearchIndex.php プロジェクト: dw250100785/Octo
 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
ファイル: TwitterUtilities.php プロジェクト: dw250100785/Octo
 /**
  * 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
ファイル: SchedulerHandler.php プロジェクト: dw250100785/Octo
 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
ファイル: Search.php プロジェクト: block8/octo
 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
ファイル: DashboardWidget.php プロジェクト: block8/octo
 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
ファイル: DashboardWidget.php プロジェクト: dw250100785/Octo
 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
ファイル: Member.php プロジェクト: block8/octo
 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
ファイル: Setting.php プロジェクト: dw250100785/Octo
 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
ファイル: SearchController.php プロジェクト: dw250100785/Octo
 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
ファイル: JobController.php プロジェクト: block8/octo
 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
ファイル: 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;
 }
コード例 #17
0
ファイル: MemberController.php プロジェクト: block8/octo
 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
ファイル: SearchIndexStore.php プロジェクト: block8/octo
 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;
 }
コード例 #19
0
 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
ファイル: DashboardController.php プロジェクト: block8/octo
 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
ファイル: bootstrap.php プロジェクト: block8/octo
$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
ファイル: ContactController.php プロジェクト: block8/octo
 public function init()
 {
     $this->contactStore = Store::get('Contact');
 }
コード例 #23
0
ファイル: JobBase.php プロジェクト: block8/octo
 public function ScheduledJobs()
 {
     return Store::get('ScheduledJob')->where('current_job_id', $this->data['id']);
 }
コード例 #24
0
ファイル: UserBase.php プロジェクト: block8/octo
 public function Permissions()
 {
     return Store::get('Permission')->where('user_id', $this->data['id']);
 }
コード例 #25
0
ファイル: SearchController.php プロジェクト: block8/octo
 public function init()
 {
     $this->searchStore = Store::get('SearchIndex');
 }
コード例 #26
0
ファイル: LogBase.php プロジェクト: block8/octo
 /**
  * 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
ファイル: Search.php プロジェクト: dw250100785/Octo
 public function __construct()
 {
     $this->searchStore = Store::get('SearchIndex');
 }
コード例 #28
0
ファイル: Log.php プロジェクト: dw250100785/Octo
 public function save()
 {
     Store::get('Log')->save($this);
 }
コード例 #29
0
ファイル: Manager.php プロジェクト: block8/octo
 /**
  * @return JobStore
  */
 protected static function getStore()
 {
     return Store::get('Job');
 }
コード例 #30
0
ファイル: ContentItemBase.php プロジェクト: block8/octo
 public function PageVersions()
 {
     return Store::get('PageVersion')->where('content_item_id', $this->data['id']);
 }