Ejemplo n.º 1
0
Archivo: Base.php Proyecto: vincium/lot
 public function __construct(\Rebond\App $app)
 {
     if ($app->site()->getStatus() == \Rebond\Core\StatusType::INACTIVE) {
         Util\Session::redirect('/error/maintenance');
     }
     parent::__construct($app);
     if ($this->signedUser->getId() != 0) {
         $this->player = \Own\Bus\Player\Data::loadByUserId($this->signedUser->getId());
         if ($this->player == null) {
             $this->player = \Own\Bus\Player\Service::create($this->signedUser);
         }
     } else {
         $this->player = new \Own\Bus\Player\Model();
     }
 }
Ejemplo n.º 2
0
Archivo: Mail.php Proyecto: vincium/lot
 public static function send($playerId, $notification)
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'user_id', 'username']);
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'email'], 'player_user');
     $options['join'][] = 'core_user player_user ON player_user.id = player.user_id';
     $options['where'][] = 'send_notification_email = 1';
     $options['where'][] = ['player.id = ?', $playerId];
     $player = \Own\Bus\Player\Data::load($options);
     if (!isset($player)) {
         return false;
     }
     // send email
     $app = \Rebond\App::instance();
     $tpl = new Util\Template(Util\Template::MODULE, ['bus', 'notification']);
     $tpl->set('url', 'http://' . \Rebond\Config::getPath('siteUrl'));
     $tpl->set('player', $player);
     $tpl->set('notification', $notification);
     $tplMail = new Util\Template(Util\Template::SITE, ['mail']);
     $tplMail->set('title', Util\Lang::lang('notification'));
     $tplMail->set('site', $app->site()->getTitle());
     $tplMail->set('url', 'http://' . \Rebond\Config::getPath('siteUrl'));
     $tplMail->set('layout', $tpl->render('notification'));
     $message = \Swift_Message::newInstance()->setContentType('text/html')->setSubject($app->site()->getTitle() . ' - ' . Util\Lang::lang('notification'))->setFrom(\Rebond\Config::getMail('email'))->setTo($player->getUser()->getEmail())->setBody($tplMail->render('tpl-default'));
     return Util\Mail::send($message);
 }
Ejemplo n.º 3
0
 public function __construct(\Rebond\App $app)
 {
     if ($app->site()->getStatus() == \Rebond\Core\StatusType::INACTIVE) {
         if ($app->ajax()) {
             return ['result' => ResultType::ERROR, 'message' => Lang::lang('error.maintenance')];
         } else {
             Util\Session::redirect('/error/maintenance');
         }
     }
     parent::__construct($app);
     if ($this->signedUser->getId() != 0) {
         $options = ['where' => [['id = ?', $this->signedUser->getId()]]];
         $this->player = \Own\Bus\Player\Data::load($options);
         if ($this->player == null) {
             $this->player = \Own\Bus\Player\Service::create($this->signedUser);
         }
     } else {
         $this->player = new \Own\Bus\Player\Model();
     }
 }
Ejemplo n.º 4
0
 protected function saveEntity()
 {
     $app = \Rebond\App::instance();
     $userId = $app->userId();
     $this->setId(0);
     $this->setAuthorId($userId);
     $workflow = $this->getModule()->getWorkflow();
     // new content
     if ($this->getContentGroup() == 0) {
         $contentGroup = Data::getNextContentGroup($this->getModuleId());
         $this->setContentGroup($contentGroup);
         if ($workflow == 1) {
             $this->setVersion(VersionType::PENDING);
         } else {
             $this->setPublisherId($userId);
             $this->setPublishedDate('now');
             $this->setVersion(VersionType::PUBLISHED);
         }
         // updating content
     } else {
         // use workflow
         if ($workflow == 1) {
             if ($this->getVersion() == VersionType::PUBLISHED) {
                 Data::updateContentGroupVersion($this, VersionType::PUBLISHED, VersionType::UPDATING);
                 $this->setVersion(VersionType::PUBLISHING);
             } else {
                 if ($this->getVersion() == VersionType::PENDING) {
                     Data::updateContentGroupVersion($this, VersionType::PENDING, VersionType::OLD);
                     $this->setVersion(VersionType::PENDING);
                 } else {
                     if (in_array($this->getVersion(), [VersionType::PUBLISHING, VersionType::UPDATING])) {
                         Data::updateContentGroupVersion($this, VersionType::PUBLISHING, VersionType::OLD);
                         $this->setVersion(VersionType::PUBLISHING);
                     }
                 }
             }
         } else {
             if ($workflow == 0) {
                 Data::updateContentGroupVersionAll($this);
                 $this->setPublisherId($userId);
                 $this->setPublishedDate('now');
                 $this->setVersion(VersionType::PUBLISHED);
             }
         }
     }
     return parent::save();
 }
Ejemplo n.º 5
0
 public static function locale($value, $params = [])
 {
     if ($value == '') {
         return $value;
     }
     $text = null;
     $log = false;
     $app = \Rebond\App::instance();
     $lang = ucfirst($app->lang());
     $xmlFilename = $app->currentSite() == \Rebond\Config::SITE_ADMIN ? 'Rebond' : 'Custom';
     $cachedFile = \Rebond\Config::getPath('rebond') . 'Cache/' . $xmlFilename . $lang . '.php';
     if (file_exists($cachedFile)) {
         $className = '\\Rebond\\Cache\\' . $xmlFilename . $lang;
         $text = $className::get($value);
         $log = true;
     }
     // try to look in admin localization if not found in front
     if (!isset($text) && $app->currentSite() == \Rebond\Config::SITE_WWW) {
         $cachedFile = \Rebond\Config::getPath('rebond') . 'Cache/Rebond' . $lang . '.php';
         if (file_exists($cachedFile)) {
             $className = '\\Rebond\\Cache\\Rebond' . $lang;
             $text = $className::get($value);
             $log = true;
         }
     }
     // try to look in site localization if not found in admin
     if (!isset($text) && $app->currentSite() == \Rebond\Config::SITE_ADMIN) {
         $cachedFile = \Rebond\Config::getPath('rebond') . 'Cache/Custom' . $lang . '.php';
         if (file_exists($cachedFile)) {
             $className = '\\Rebond\\Cache\\Custom' . $lang;
             $text = $className::get($value);
             $log = true;
         }
     }
     if (!isset($text)) {
         if ($log) {
             Log::log(Error::LANG_NOT_FOUND, 'lang: ' . $lang . ', site: ' . $app->currentSite() . ', value: ' . $value, __FILE__, __LINE__);
         }
         return trim($value) . '~';
     }
     $count = count($params);
     for ($i = 0; $i < $count; $i++) {
         $text = str_replace('{' . $i . '}', $params[$i], $text);
     }
     $text = trim(preg_replace('/{\\d+}/', '', $text));
     return $text;
 }
Ejemplo n.º 6
0
 public static function log($code, $message, $file, $line)
 {
     $app = \Rebond\App::instance();
     $d = new \DateTime();
     $message = self::textify($message);
     if ($app->step() != \Rebond\Config::STEP_RUNNING) {
         $log = \Rebond\Config::getPath('log') . 'log.txt';
         $file = str_replace(FULL_PATH, '/', str_replace('\\', '/', $file));
         $trace = stripos($file, 'SplClassLoader') !== false ? self::textify(debug_backtrace()) : '';
         // date # code # message # trace # file # line
         $message = $d->format('Y-m-d H:i:s') . '#' . Error::value($code) . '#' . str_replace(FULL_PATH, '/', $message) . '#' . $trace . '#' . $file . '#' . $line . PHP_EOL;
         \Rebond\Util\File::save($log, 'a', $message);
     } else {
         if (!in_array($code, [Error::LANG_NOT_FOUND, Error::PAGE_NOT_FOUND]) && $app->env() == \Rebond\Config::ENV_PROD && $app->site()->getSendMailOnError()) {
             $emails = $app->site()->getMailListOnError();
             if ($emails != '') {
                 $emails = explode(',', $emails);
                 \Rebond\App\Error\Mail::error($app->site()->getTitle(), $emails, $code, $message, $file, $line);
             }
         }
         $log = null;
         if ($code == Error::LANG_NOT_FOUND) {
             $options = [];
             $options['where'][] = ['log.request_uri = ?', $_SERVER['REQUEST_URI']];
             $options['where'][] = ['log.message = ?', $message];
             $log = \Rebond\Core\Log\Data::load($options);
         }
         if (!isset($log)) {
             $log = new \Rebond\Core\Log\Model();
             $log->setCode($code);
             $log->setMessage($message);
             $log->setRequestUri($_SERVER['REQUEST_URI']);
         }
         $log->setUserId($app->userId());
         $log->setFile($file);
         $log->setLine($line);
         $log->setTrace(self::textify(debug_backtrace()));
         $log->setIp($_SERVER['REMOTE_ADDR']);
         $log->setReferer(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
         return $log->save();
     }
     return 0;
 }
Ejemplo n.º 7
0
 private function log()
 {
     $app = \Rebond\App::instance();
     $app->queryCount(1);
     if (\Rebond\App::instance()->site()->getSqlLog() && strpos($this->statement, 'core_log') === false && (strpos($this->statement, 'bus_') !== false || strpos($this->statement, 'app_') !== false)) {
         $pos = strpos($this->statement, 'FROM');
         Log::log(Error::SQL_LOG, $app->queryCount() . ' - ' . substr($this->statement, $pos), __FILE__, __LINE__);
         $app->queryCount(-1);
     }
 }
Ejemplo n.º 8
0
 public function __construct($path, $folders)
 {
     $this->vars = [];
     $this->pathSetter($path, $folders);
     $this->app = \Rebond\App::instance();
 }
Ejemplo n.º 9
0
 public static function isPreview()
 {
     if (!isset($_GET['preview']) || $_GET['preview'] != '1') {
         return false;
     }
     $user = \Rebond\App::instance()->user();
     if (!Auth::isAuthorized($user, 'admin.preview')) {
         return false;
     }
     return true;
 }
Ejemplo n.º 10
0
 public static function kill($code, $error, $file, $line)
 {
     $app = \Rebond\App::instance();
     $redirect = (int) Session::get('redirect');
     if ($redirect > 5) {
         $app->setStep(\Rebond\Config::STEP_REDIRECT);
     } else {
         Session::set('redirect', $redirect + 1);
     }
     $logId = Log::log($code, $error, $file, $line);
     $json = [];
     $json['result'] = ResultType::ERROR;
     if ($app->step() != \Rebond\Config::STEP_RUNNING) {
         if ($app->ajax()) {
             $json['message'] = Lang::locale('configurationError');
             echo json_encode($json);
             exit;
         } else {
             $controller = new \Rebond\Controller\Admin\Error($app);
             echo $controller->config();
             session_write_close();
             exit;
         }
     } else {
         // update log level if user isDev
         $app->user();
         if ($app->logLevel() == 0) {
             if ($app->ajax()) {
                 $json['message'] = Lang::lang('serviceNotAvailable') . ': ' . $error . ' [<a href="http://' . \Rebond\Config::getPath('adminUrl') . '/tools/log" target="_blank">' . Lang::lang('logsView') . '</a>]';
                 echo json_encode($json, JSON_UNESCAPED_SLASHES);
                 exit;
             } else {
                 if (in_array($code, [self::PAGE_NOT_FOUND, self::ADMIN_PAGE_NOT_FOUND])) {
                     header('Location: /error/generic?404=' . $error);
                 } else {
                     header('Location: /error/detail?id=' . $logId);
                 }
                 session_write_close();
                 exit;
             }
         } else {
             if ($app->ajax()) {
                 $json['message'] = Lang::lang('errorUnknown');
                 echo json_encode($json);
                 exit;
             } else {
                 if (in_array($code, [self::PAGE_NOT_FOUND, self::ADMIN_PAGE_NOT_FOUND])) {
                     header('Location: /error/generic?404=' . $error);
                 } else {
                     header('Location: /error/generic');
                 }
                 session_write_close();
                 exit;
             }
         }
     }
 }
Ejemplo n.º 11
0
 public function __construct(\Rebond\App $app)
 {
     $app->setAjax(true);
     parent::__construct($app);
 }
Ejemplo n.º 12
0
 public function __construct(\Rebond\App $app)
 {
     $app->setAjax(true);
     parent::__construct($app);
     $this->signedUser = $this->app->user();
 }
Ejemplo n.º 13
0
 public function renderScore($evenNotViewed = false)
 {
     if (null === $this->getPlayerMatch1() || null === $this->getPlayerMatch2()) {
         return $this->getScheduled()->format();
     }
     if ($this->getStatus() <= MatchStatus::READY) {
         return $this->getScheduled()->format();
     }
     if (!$evenNotViewed) {
         $userId = \Rebond\App::instance()->userId();
         if ($userId == $this->getPlayerMatch1()->getPlayer()->getUserId() && !$this->getPlayerMatch1()->getHasViewed() || $userId == $this->getPlayerMatch2()->getPlayer()->getUserId() && !$this->getPlayerMatch2()->getHasViewed()) {
             return '?';
         }
     }
     $winnerId = $this->findWinnerId();
     $playerMatch1 = $this->getPlayerMatch1();
     $playerMatch2 = $this->getPlayerMatch2();
     if ($winnerId != 0 && $winnerId == $this->getPlayerMatch2Id()) {
         $playerMatch1 = $this->getPlayerMatch2();
         $playerMatch2 = $this->getPlayerMatch1();
     }
     $score = $playerMatch1->getSet1() . '/' . $playerMatch2->getSet1();
     if ($this->getCurrentSet() >= 2 && ($playerMatch1->getSet2() != 0 || $playerMatch2->getSet2() != 0)) {
         $score .= ' ' . $playerMatch1->getSet2() . '/' . $playerMatch2->getSet2();
     }
     if ($this->getCurrentSet() >= 3 && ($playerMatch1->getSet3() != 0 || $playerMatch2->getSet3() != 0)) {
         $score .= ' ' . $playerMatch1->getSet3() . '/' . $playerMatch2->getSet3();
     }
     if ($this->getCurrentSet() >= 4 && ($playerMatch1->getSet4() != 0 || $playerMatch2->getSet4() != 0)) {
         $score .= ' ' . $playerMatch1->getSet4() . '/' . $playerMatch2->getSet4();
     }
     if ($this->getCurrentSet() >= 5 && ($playerMatch1->getSet5() != 0 || $playerMatch2->getSet5() != 0)) {
         $score .= ' ' . $playerMatch1->getSet5() . '/' . $playerMatch2->getSet5();
     }
     return $score;
 }