/**
  * crypt password
  * Defines whether to use bcrypt or salted MD5
  * @param $val
  * @return string
  */
 public function set_password($val)
 {
     $f3 = \Base::instance();
     if (!$val) {
         $userDetails = new self();
         $userDetails->load(array('username = ?', $f3->get('POST.username')));
         $val = $userDetails->password;
         return $val;
     } else {
         $hash_engine = $f3->get('password_hash_engine');
         switch ($hash_engine) {
             case 'bcrypt':
                 $crypt = \Bcrypt::instance();
                 $val = $crypt->hash($val);
                 break;
             case 'md5':
                 // fall-through
             // fall-through
             default:
                 $val = md5($val . $f3->get('password_md5_salt'));
                 break;
         }
         return $val;
     }
 }
Exemplo n.º 2
0
 function get()
 {
     $f3 = \Base::instance();
     $f3->set('AUTOLOAD', $f3->get('AUTOLOAD') . ';app/cortex/');
     $f3->set('QUIET', false);
     $dbs = array('sql' => new \DB\SQL('mysql:host=localhost;port=3306;dbname=fatfree', 'fatfree', ''), 'jig' => new \DB\Jig('data/'), 'mongo' => new \DB\Mongo('mongodb://localhost:27017', 'testdb'));
     $results = array();
     // Test Syntax
     foreach ($dbs as $type => $db) {
         $test = new \Test_Syntax();
         $results = array_merge((array) $results, (array) $test->run($db, $type));
     }
     // Test Relations
     foreach ($dbs as $type => $db) {
         $f3->set('DB', $db);
         $test = new \Test_Relation();
         $results = array_merge((array) $results, (array) $test->run($db, $type));
     }
     // Test Filter
     foreach ($dbs as $type => $db) {
         $f3->set('DB', $db);
         $test = new \Test_Filter();
         $results = array_merge((array) $results, (array) $test->run($db, $type));
     }
     // Further Common Tests
     if (isset($dbs['sql'])) {
         $test = new \Test_Common();
         $f3->set('DB', $dbs['sql']);
         $results = array_merge((array) $results, (array) $test->run());
     }
     $f3->set('results', $results);
 }
Exemplo n.º 3
0
 function __construct() {
     $f3 = Base::instance();
     $dbh = new PDO($f3->get('db_dns') . $f3->get('db_name'), $f3->get('db_user'), $f3->get('db_pass'));
     $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $this->f3 = $f3;
     $this->db = $dbh;
 }
Exemplo n.º 4
0
 public function __construct()
 {
     $this->f3 = \Base::instance();
     $this->supportedLanguages = $this->f3->get('SUPPORTED_LANGUAGES');
     $this->fallback = $this->f3->get('FALLBACK');
     $this->setLanguage($this->detectLanguage());
 }
Exemplo n.º 5
0
 function __construct()
 {
     $f3 = Base::instance();
     $db = new DB\SQL($f3->get('db_dns') . $f3->get('db_name'), $f3->get('db_user'), $f3->get('db_pass'));
     $this->f3 = $f3;
     $this->db = $db;
 }
Exemplo n.º 6
0
 function GetPass()
 {
     $key = \Base::instance()->get('APP_KEY');
     $crypt = new \Helper\Crypt($key);
     $text = $this->get('root_pass');
     return $crypt->decrypt($text);
 }
Exemplo n.º 7
0
 protected function displayEdit()
 {
     $item = $this->getItem();
     if (empty($item) || $item->product_type != 'giftcards') {
         \Dsc\System::addMessage('Item is not a giftcard', 'error');
         $this->app->reroute('/admin/shop/giftcards');
     }
     $f3 = \Base::instance();
     $flash = \Dsc\Flash::instance();
     $variants = array();
     if ($flashed_variants = $flash->old('variants')) {
         foreach ($flashed_variants as $variant) {
             $key = implode("-", (array) $variant['attributes']);
             if (empty($key)) {
                 $key = $variant['id'];
             }
             $variants[$key] = $variant;
         }
     }
     $old = array_merge($flash->get('old'), array('variants' => $variants));
     $flash->store($old);
     $model = new \Shop\Models\Categories();
     $categories = $model->getList();
     \Base::instance()->set('categories', $categories);
     \Base::instance()->set('selected', 'null');
     $all_tags = $this->getModel()->getTags();
     \Base::instance()->set('all_tags', $all_tags);
     $this->app->set('meta.title', 'Edit Gift Card | Shop');
     $view = \Dsc\System::instance()->get('theme');
     $view->event = $view->trigger('onDisplayShopProductsEdit', array('item' => $this->getItem(), 'tabs' => array(), 'content' => array()));
     echo $view->render('Shop\\Admin\\Views::giftcards/edit.php');
 }
Exemplo n.º 8
0
 /**
  * init the model
  */
 public function __construct()
 {
     $f3 = \Base::instance();
     $this->table = $f3->get('db_table_prefix') . $this->table;
     $this->db = 'DB';
     parent::__construct();
     // validation & error handler
     $class = get_called_class();
     // PHP 5.3 bug
     $saveHandler = function (\DB\Cortex $self) use($class) {
         $valid = true;
         foreach ($self->getFieldConfiguration() as $field => $conf) {
             if (isset($conf['type'])) {
                 $val = $self->get($field);
                 $model = strtolower(str_replace('\\', '.', $class));
                 // check required fields
                 if (isset($conf['required'])) {
                     $valid = \Validation::instance()->required($val, $field, 'error.' . $model . '.' . $field);
                 }
                 // check unique
                 if (isset($conf['unique'])) {
                     $valid = \Validation::instance()->unique($self, $val, $field, 'error.' . $model . '.' . $field);
                 }
                 if (!$valid) {
                     break;
                 }
             }
         }
         return $valid;
     };
     $this->beforesave($saveHandler);
 }
Exemplo n.º 9
0
 public function createpost()
 {
     // Log-in stuff
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
 }
Exemplo n.º 10
0
 public function index()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org_links = $f3->get('user_org_links');
     $db = $f3->get('db.instance');
     $tickets = $db->exec('SELECT * FROM support_tickets WHERE memberId = ? ORDER BY id DESC', $user['id']);
     foreach ($tickets as $id => $ticket) {
         $result = $db->exec('SELECT COUNT(*) AS `count` FROM support_tickets_msg WHERE ticketId = ?', $ticket['id']);
         $tickets[$id]['messages_count'] = $result[0]['count'];
         // Assigned or not ?
         if ($ticket['assignedUserId'] != 0) {
             $assignedUser = new User();
             $assignedUser->load($ticket['assignedUserId']);
             $tickets[$id]['assignedUser'] = $assignedUser->cast();
         }
     }
     $f3->set('tickets', $tickets);
     $active_tickets = $db->exec("SELECT * FROM support_tickets WHERE memberId = ? AND status != 'closed'", $user['id']);
     $f3->set('active_tickets', $active_tickets);
     $closed_tickets = $db->exec("SELECT * FROM support_tickets WHERE memberId = ? AND status = 'closed'", $user['id']);
     $f3->set('closed_tickets', $closed_tickets);
     $f3->set('target', 'support/index.html');
     $this->_render('base.html');
 }
Exemplo n.º 11
0
 function reroute($url)
 {
     if ($this->dry()) {
         Base::instance()->reroute($url);
     }
     return $this;
 }
Exemplo n.º 12
0
 public static function libraryBookFavMenu(array $menu, array $counter, $sub)
 {
     \Base::instance()->set('menu_upper', $menu);
     \Base::instance()->set('counter', $counter);
     \Base::instance()->set('sub', $sub);
     return \Template::instance()->render('usercp/menu_upper.html');
 }
 public function getItemsTransactionsByDateTime()
 {
     $operator = Base::instance()->get('PARAMS[operator]');
     $date = Base::instance()->get('PARAMS[date]');
     $time = Base::instance()->get('PARAMS[time]');
     echo json_encode(ItemTransaction::getItemsTransactionsByDateTime($operator, $date, $time));
 }
Exemplo n.º 14
0
 function render()
 {
     // Clean all output given first
     while (ob_get_level()) {
         ob_end_clean();
     }
     $f3 = \Base::instance();
     $f3->set('headline', 'Error ' . $f3->get('ERROR.code'));
     $f3->set('text', $f3->get('ERROR.text'));
     $f3->set('ESCAPE', false);
     if ($f3->get('AJAX')) {
         die(json_encode(array('error' => $f3->get('ERROR.text'))));
     }
     if ($f3->get('ERROR.code') == 400) {
         \Flash::instance()->addMessage($f3->get('ERROR.text'), 'warning');
         $f3->set('HALT', false);
         return;
     } elseif ($f3->get('ERROR.code') == 404) {
         $f3->set('headline', 'Page not found');
     } elseif ($f3->get('ERROR.code') == 405) {
         $f3->set('headline', 'This action is not allowed');
     } elseif ($f3->get('ERROR.code') == 500) {
         $f3->set('headline', 'Internal Server Error');
         if ($f3->get('DEV')) {
             $f3->set('trace', $f3->highlight($f3->get('ERROR.trace')));
         }
         @mail($f3->get('error_mail'), 'Mth3l3m3nt Framework Error', $f3->get('ERROR.text') . "\n\n" . $f3->get('ERROR.trace'));
     }
     $f3->set('LAYOUT', 'error.html');
     $f3->set('HALT', true);
     echo \Template::instance()->render('themes/default/layout.html');
 }
Exemplo n.º 15
0
 public function select()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $f3->set('SESSION.selected_organisation', $f3->get('PARAMS.id'));
     $f3->reroute('/organisations');
 }
Exemplo n.º 16
0
 /**
  * Allows admins do create a new user
  *
  * @url /dashboard/admin/users/create
  */
 public function createpost()
 {
     $f3 = \Base::instance();
     // Login requires
     $this->_requireLogin();
     $this->_requireRank('support');
     // Create user
     $user = User::createUser(array('name' => $f3->get("POST.name"), 'username' => $f3->get("POST.username"), 'email' => $f3->get("POST.email"), 'password' => $f3->get("POST.password")));
     // Data missing
     if ($user == false) {
         $f3->set('errors', ['Some information has not been entered correctly or is not long enough.']);
     } elseif (is_array($user)) {
         $f3->set('errors', $user);
     } else {
         // Redirect to that user's info page OR stay at this page
         if ($f3->exists('POST.disable-user-forward')) {
             $f3->reroute($f3->get('PATH'));
         } else {
             $f3->reroute("/dashboard/admin/users/details/" . $user->id);
         }
         return;
     }
     $f3->set('target', 'dashboard/admin/users/details.html');
     $this->_render('base.html');
 }
Exemplo n.º 17
0
 public function index()
 {
     // when ACL is ready
     // $this->checkAccess( __CLASS__, __FUNCTION__ );
     $model = $this->getModel();
     $state = $model->populateState()->getState();
     \Base::instance()->set('state', $state);
     $paginated = $model->paginate();
     \Base::instance()->set('paginated', $paginated);
     $categories_db = (array) $this->getModel("categories")->getItems();
     $categories = array(array('text' => 'All Categories', 'value' => ' '), array('text' => '- Uncategorized -', 'value' => '--'));
     array_walk($categories_db, function ($cat) use(&$categories) {
         $categories[] = array('text' => $cat->title, 'value' => (string) $cat->slug);
     });
     \Base::instance()->set('categories', $categories);
     $all_tags = array(array('text' => 'All Tags', 'value' => ' '), array('text' => '- Untagged -', 'value' => '--'));
     $tags = (array) $this->getModel()->getTags();
     array_walk($tags, function ($tag) use(&$all_tags) {
         $all_tags[] = array('text' => $tag, 'value' => $tag);
     });
     \Base::instance()->set('all_tags', $all_tags);
     $this->app->set('meta.title', 'Posts | Blog');
     $this->app->set('allow_preview', $this->canPreview(true));
     $view = \Dsc\System::instance()->get('theme');
     echo $view->render('Blog/Admin/Views::posts/list.php');
 }
Exemplo n.º 18
0
 /**
  * Let's users integrate subscribe buttons into their website
  */
 public function index()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org_links = $f3->get('user_org_links');
     if (count($user_org_links) == 0) {
         $f3->reroute('/dashboard');
     } else {
         // Home-page stats
         if ($f3->exists('SESSION.selected_organisation')) {
             $orgId = $f3->get('SESSION.selected_organisation');
             foreach ($user_org_links as $orgKey => $orgValue) {
                 if ($orgValue['orgId'] == $orgId) {
                     $validated = true;
                 }
             }
         }
         // Total views
         if (!isset($validated)) {
             // Select first
             $orgId = $user_org_links[0]['orgId'];
         }
         $totalViews = $f3->get('db.instance')->exec('SELECT * FROM newsletter_opens WHERE orgId = ?', $orgId);
         $f3->set('totalViews', count($totalViews));
         $orgMap = new \Models\Organisation();
         $orgMap->load($orgId);
         $f3->set('user_org_selected', $orgMap->cast());
         $f3->set('target', 'dashboard/integrations/index/index.html');
     }
     $this->_render('base.html');
 }
Exemplo n.º 19
0
 public static function flash($key)
 {
     $fw = Base::instance();
     $content = $fw->get('SESSION.' . $key);
     $fw->clear('SESSION.' . $key);
     return $content;
 }
Exemplo n.º 20
0
 private function __construct()
 {
     $this->tablesManager = TablesManager::getInstance();
     $this->metaWriter = MetaManager::getInstance();
     $this->db = \Base::instance()->get('db');
     $this->debugState = \Base::instance()->get('DEBUG');
 }
Exemplo n.º 21
0
 /**
  *	Return weather data based on specified latitude/longitude
  *	@return array|FALSE
  *	@param $latitude float
  *	@param $longitude float
  **/
 function weather($latitude, $longitude)
 {
     $fw = \Base::instance();
     $web = \Web::instance();
     $query = array('lat' => $latitude, 'lng' => $longitude, 'username' => $fw->hash($fw->get('IP')));
     return ($req = $web->request('http://ws.geonames.org/findNearByWeatherJSON?' . http_build_query($query))) && ($data = json_decode($req['body'], TRUE)) && isset($data['weatherObservation']) ? $data['weatherObservation'] : FALSE;
 }
Exemplo n.º 22
0
 function __construct()
 {
     $this->f3 = $f3 = \Base::instance();
     $this->event = \Base::instance()->get('SESSION.event');
     $this->pusher = new \Pusher($this->f3->get('pusher_key'), $this->f3->get('pusher_secret'), $this->f3->get('pusher_app_id'));
     //	parent::__construct();
 }
Exemplo n.º 23
0
 /**
  * This controller doesn't allow reading, only editing, so redirect to the edit method
  */
 protected function doRead(array $data, $key = null)
 {
     $f3 = \Base::instance();
     $id = $this->getItem()->get($this->getItemKey());
     $route = str_replace('{id}', $id, $this->edit_item_route);
     $f3->reroute($route);
 }
Exemplo n.º 24
0
 public function post()
 {
     $f3 = \Base::instance();
     $userId = User::getUserId($f3->get("POST.username"));
     if ($userId) {
         if (User::verifyUserPassword($userId, $f3->get("POST.password"))) {
             $user = User::getUser($userId);
             // Check if the user is suspended
             if ($user->suspended_time != null) {
                 $f3->set('error', sprintf('Your account is suspended since %s, check your email.', $user->suspended_time));
             } else {
                 // GO GO GO !
                 $f3->set('SESSION.id', $user->id);
                 $f3->reroute("/dashboard");
                 return;
             }
         } else {
             $f3->set('error', 'Wrong username/password combination');
         }
     } else {
         $f3->set('error', 'Wrong username/password combination');
     }
     $f3->set('css', array('/static/css/auth.css'));
     $f3->set('target', 'auth/login.html');
     $this->_render('base.html');
 }
Exemplo n.º 25
0
 /**
  *	Forward function calls to framework
  *	@return mixed
  *	@param $func callback
  *	@param $args array
  **/
 static function __callstatic($func, array $args)
 {
     if (!self::$fw) {
         self::$fw = Base::instance();
     }
     return call_user_func_array([self::$fw, $func], $args);
 }
Exemplo n.º 26
0
 /**
  *	Instantiate class
  *	@param $dsn string
  *	@param $dbname string
  *	@param $options array
  **/
 function __construct($dsn, $dbname, array $options = NULL)
 {
     $this->uuid = \Base::instance()->hash($this->dsn = $dsn);
     $class = class_exists('\\MongoClient') ? '\\MongoClient' : '\\Mongo';
     $this->db = new \MongoDB(new $class($dsn, $options ?: array()), $dbname);
     $this->setprofilinglevel(2);
 }
Exemplo n.º 27
0
 public function html()
 {
     \Base::instance()->set('module', $this);
     \Dsc\System::instance()->get('theme')->registerViewPath(__DIR__ . '/Views/', 'Modules/Html/Views');
     $string = \Dsc\System::instance()->get('theme')->renderLayout('Modules/Html/Views::default.php');
     return $string;
 }
Exemplo n.º 28
0
 public function index()
 {
     $f3 = \Base::instance();
     $path = $this->inputfilter->clean($f3->get('PARAMS.1'), 'string');
     $model = $this->getModel();
     try {
         $category = (new \Blog\Models\Categories())->setState('filter.path', $path)->getItem();
         if (empty($category->id)) {
             throw new \Exception();
         }
         $paginated = $model->populateState()->setState('filter.category.id', $category->id)->setState('filter.publication_status', 'published')->setState('filter.published_today', true)->paginate();
     } catch (\Exception $e) {
         \Dsc\System::instance()->addMessage("Invalid Items", 'error');
         $f3->reroute('/blog');
         return;
     }
     $state = $model->getState();
     \Base::instance()->set('state', $state);
     \Base::instance()->set('paginated', $paginated);
     \Base::instance()->set('category', $category);
     $this->app->set('meta.title', $category->seoTitle() . ' | Blog');
     $this->app->set('meta.description', $category->seoDescription());
     $view = \Dsc\System::instance()->get('theme');
     echo $view->render('Blog/Site/Views::categories/index.php');
 }
Exemplo n.º 29
0
 /**
  * create FAL on local filesystem as prefab default
  * @return mixed
  */
 public static function instance()
 {
     $f3 = \Base::instance();
     $dir = $f3->split($f3->get('UI'));
     $localFS = new \FAL\LocalFS($dir[0]);
     return new self($localFS);
 }
Exemplo n.º 30
0
 /**
  * Write session data
  * 
  * @return TRUE
  * @param $id string            
  * @param $data string            
  *
  */
 function write($id, $data)
 {
     $fw = \Base::instance();
     $sent = headers_sent();
     $headers = $fw->get('HEADERS');
     if ($id != $this->__session_id) {
         $sessionData = static::collection()->findOne(array('session_id' => $this->__session_id = $id));
         if (isset($sessionData['_id'])) {
             $this->bind($sessionData);
         }
     }
     $csrf = $fw->hash($fw->get('ROOT') . $fw->get('BASE')) . '.' . $fw->hash(mt_rand());
     $this->set('session_id', $id);
     $this->set('data', $data);
     $this->set('csrf', $sent ? $this->csrf() : $csrf);
     $this->set('ip', $fw->get('IP'));
     $this->set('agent', isset($headers['User-Agent']) ? $headers['User-Agent'] : '');
     $this->set('timestamp', time());
     $this->store();
     if (!$sent) {
         if (isset($_COOKIE['_'])) {
             setcookie('_', '', strtotime('-1 year'));
         }
         call_user_func_array('setcookie', array('_', $csrf) + $fw->get('JAR'));
     }
     return true;
 }