Exemplo n.º 1
0
 public static function hash($str)
 {
     $salt = Configure::read(CMS::SaltConfigureKey);
     $salt = md5($salt);
     $result = crypt($str, $salt);
     return $result;
 }
Exemplo n.º 2
0
 public function setUp()
 {
     parent::setUp();
     $model = new TestDocument();
     $model->createDatabaseTable(true);
     Helper::dbFixture(SITEMAP_TABLE, []);
     \ACL::create(SitemapModel::PermissionName);
     Configure::write('Sitemap', ['Menu' => ['title' => self::Title, 'depth' => 3]]);
     Helper::setupUsers([['login' => self::AdminUser, 'rights' => [SitemapModel::PermissionName => true]], ['login' => self::GuestUser]]);
     $documents = [['name' => 'first', 'sitemap' => ['count' => 1]], ['name' => 'second'], ['name' => 'third', 'sitemap' => ['parent' => 1]]];
     foreach ($documents as $key => $row) {
         $documents[$key] = new TestDocument($row);
         $documents[$key]->insert();
         $sitemapModel = new SitemapModel();
         $sitemapModel->name = $row['name'];
         $sitemapModel->full_url = $row['name'];
         $sitemapModel->linkToModel($documents[$key]);
         if (isset($row['sitemap'])) {
             foreach ($row['sitemap'] as $key => $value) {
                 $sitemapModel->{$key} = $value;
             }
         }
         $sitemapModel->insert();
     }
 }
Exemplo n.º 3
0
 public function testScriptLoaded()
 {
     Configure::write(RestartServer::ConfigureKey, __DIR__ . '/4restart_server.php');
     //
     $api = new RestartServer();
     $api->exec();
     $this->assertTrue(self::$called);
 }
Exemplo n.º 4
0
 public function testHelperConfigurable()
 {
     Configure::write(SitemapTemplateHelper::ConfigureKey, '');
     $this->assertEquals(SitemapTemplateHelper::getViewPath(), SitemapTemplateHelper::getViewPath());
     //
     Configure::write(SitemapTemplateHelper::ConfigureKey, self::getViewPath());
     $this->assertEquals($this->getViewPath(), SitemapTemplateHelper::getViewPath());
 }
Exemplo n.º 5
0
 public function testOutputFolderConfigurable()
 {
     Configure::write(Writer::ConfigureKey, '');
     $result = SYS_ROOT . Writer::AppFolderName;
     $this->assertEquals($result, Writer::getCacheFolderPath());
     $fixture = 'hello';
     Configure::write(Writer::ConfigureKey, $fixture);
     $this->assertEquals($fixture, Writer::getCacheFolderPath());
 }
Exemplo n.º 6
0
 protected function autoloadConfig()
 {
     $this->config = \Faid\Configure\Configure::read(self::ConfigurePath);
     $valid = isset($this->config['servers']) && is_array($this->config['servers']);
     if (!$valid) {
         throw new Exception('Memcache config not valid');
     }
     $this->prefix = !empty($this->config['prefix']) ? $this->config['prefix'] : '';
 }
Exemplo n.º 7
0
 public function __construct($data = [])
 {
     parent::__construct($data);
     try {
         $this->limit = Configure::read(self::ConfigureKey);
     } catch (\Exception $e) {
         $this->limit = self::DefaultLimit;
     }
 }
Exemplo n.º 8
0
 protected function getTimeLimit()
 {
     try {
         $result = Configure::read(self::TimeoutConfigureKey);
     } catch (ConfigureException $e) {
         $result = 1;
     }
     return $result;
 }
Exemplo n.º 9
0
 protected function autoloadMenuItems()
 {
     try {
         $menuItems = Configure::read(self::AutoloadMenuItemsConfigureKey);
     } catch (ConfigureException $e) {
         return;
     }
     $menuItems = \EventController::callFilter(self::FilterName, $menuItems);
     foreach ($menuItems as $item) {
         $this->items->add($item);
     }
 }
Exemplo n.º 10
0
 public function setUp()
 {
     parent::setUp();
     $path = EXTASY_PATH . self::CacheFolder;
     //
     $fs = DAO_FileSystem::getInstance();
     $fs->createPath($path);
     //
     Configure::write(Writer::ConfigureKey, $path);
     //
     $this->cleanStaticApplicationCacheFolder();
 }
Exemplo n.º 11
0
 public static function getViewPath()
 {
     try {
         $result = Configure::read(self::ConfigureKey);
     } catch (ConfigureException $e) {
         $result = '';
     }
     if (empty($result)) {
         $result = VIEW_PATH;
     }
     return $result;
 }
Exemplo n.º 12
0
 public static function restore()
 {
     $data = array('Audit' => array('notification_emails' => '', 'maximumLogLength' => 65536), 'Security' => array('salt' => '123', 'LoginAttempts' => array('PerSession' => 5, 'PerHost' => 10), 'DDosDetector' => ['MaxConnections' => 1000, 'Message' => '', 'Period' => '1 minute']), 'Schedule' => array('runningFlag' => '0'), 'Sitemap' => array('visible' => 'false'), 'email' => array('use_standart_mail_function' => 0, 'enable_ssl' => 0, 'smtp_server' => 0, 'smtp_port' => '', 'smtp_user' => '', 'smtp_password' => '', 'from_email' => '', 'from_name' => ''), 'Front-end' => array('enable_debug' => true, 'pack' => 0, 'technical_message' => '', 'need_cms_auth' => false));
     self::restorePath('/System/', $data);
     $applicationImport = array('users' => array('captcha_provider' => 'none', 'registration_need_email' => 1, 'front-end' => ['account_confirmation' => 1, 'account_registration_success_email' => 0]));
     self::restorePath('/Applications/', $applicationImport);
     self::restoreImageColumnConfig();
     $usersConfig = array('table' => \UserAccount::TableName, 'fields' => array('id' => '\\Extasy\\Columns\\Index', 'login' => '\\Extasy\\Users\\Columns\\Login', 'email' => '\\Extasy\\Users\\Columns\\Email', 'new_email' => '\\Extasy\\Columns\\Input', 'name' => '\\Extasy\\Columns\\Input', 'avatar' => array('class' => '\\Extasy\\Columns\\Image', 'base_dir' => 'users/', 'images' => ''), 'password' => '\\Extasy\\Columns\\Password', 'rights' => '\\GrantColumn', 'last_activity_date' => '\\Extasy\\Columns\\Datetime', 'confirmation_code' => '\\Extasy\\Users\\Columns\\ConfirmationCode', 'email_confirmation_code' => '\\Extasy\\Columns\\Input', 'time_access' => '\\Extasy\\Users\\Columns\\TimeAccess', 'social_networks' => '\\Extasy\\Users\\Columns\\SocialNetworks'));
     Configure::write(\UserAccount::ModelConfigureKey, $usersConfig);
     $data = array('cconfig' => array('user_control_path' => array()));
     self::restorePath('/Applications/', $data);
     \SystemRegisterSample::createCache();
 }
Exemplo n.º 13
0
Arquivo: DB.php Projeto: gudwin/faid
 /**
  * Check if connection with mysql server was established or not
  */
 public static function checkConnection()
 {
     if (!empty(self::$connection)) {
         // connection established, exit function
     } else {
         // no, we have to connect Mysql-server
         $data = Configure::read('DB');
         self::$connection = new \mysqli($data['host'], $data['user'], $data['password'], $data['database'], isset($data['port']) ? $data['port'] : null, isset($data['socket']) ? $data['socket'] : null);
         if (self::$connection->connect_error) {
             $msg = sprintf('DB failed to connect mysql server. Mysql respone - %s', self::$connection->connect_error);
             throw new \Exception($msg);
         }
         self::$connection->set_charset('utf8');
     }
 }
Exemplo n.º 14
0
 protected function loadConfigurationFile()
 {
     try {
         $sql = sprintf('truncate %s ', Job::TableName);
         DB::post($sql);
         $path = \Faid\Configure\Configure::read(self::ConfigureKey);
         $validator = new ReadableFile($path);
         if ($validator->isValid()) {
             include $path;
         }
         \CMSLog::addMessage(__CLASS__, 'Schedule restarted');
     } catch (\Exception $e) {
         \CMSLog::addMessage(__CLASS__, $e);
         return ['error' => 'internal error'];
     }
     return;
 }
Exemplo n.º 15
0
 /**
  *   @desc Обрабатываем запрос и пересылаем на вывод
  *   @return
  */
 public function post($sql)
 {
     $this->szError = '';
     $this->aResult = array();
     // Замеряем время
     $timeStart = microtime(true);
     $connection = Configure::read('DB');
     $mysql = new mysqli($connection['host'], $connection['user'], $connection['password'], $connection['database']);
     $mysql->set_charset('utf8');
     $result = $mysql->query($sql);
     $timeFinish = microtime(true);
     // Если у запроса есть результаты
     if ($result !== FALSE) {
         // Если имеется результат запроса
         if (!is_bool($result)) {
             $row = $result->fetch_assoc();
             while ($row) {
                 $this->aResult[] = $row;
                 $row = $result->fetch_assoc();
             }
         }
     } else {
         $result = array();
         $this->szError = $mysql->error;
     }
     array_push($this->aSession, $sql);
     $_SESSION['cms_sql_query_time'] = $timeFinish - $timeStart;
     // Выводим результат запроса
     ob_start();
     $this->outputResults();
     $content = ob_get_clean();
     // Получаем последний список запросов
     ob_start();
     $this->outputSessionRequests();
     $requests = ob_get_clean();
     // Вывод блока ошибки
     ob_start();
     $this->outputError();
     $error = ob_get_clean();
     // Время запроса
     $time = $_SESSION['cms_sql_query_time'];
     // Формируем результат
     $output = array('request' => $sql, 'time' => $time, 'sql_log' => $requests, 'error' => $error, 'size' => sizeof($result), 'results' => $content);
     print json_encode($output);
     die;
 }
Exemplo n.º 16
0
 /**
  *
  */
 public function __construct($urlInfo = array())
 {
     parent::__construct($urlInfo);
     // confirmation page
     $this->addGet('code', 'confirm');
     $this->addPost('code', 'confirm');
     $this->addGet('email_confirmation_code', 'confirmEmail');
     // after regstration page
     $this->addGet('success', 'showSuccess');
     // submit page
     $this->AddPost('login,password,email', 'signup');
     $register = new SystemRegister('Applications/users');
     $captcha_provider = $register->captcha_provider->value;
     if ('recaptcha' == $captcha_provider) {
         require_once LIB_PATH . '3rdparty/recaptchalib.php';
         $config = \Faid\Configure\Configure::read('Recaptcha');
         $this->recaptchaPublicKey = $config['public_key'];
         $this->recaptchaPrivateKey = $config['private_key'];
     }
 }
Exemplo n.º 17
0
 public function testLastRecordsReturned()
 {
     $count = 2;
     $data = ['first', 'second', 'third'];
     foreach ($data as $row) {
         $job = new TestAction();
         $job->hash = $row;
         $job->insert();
     }
     Configure::write(Latests::ConfigureKey, $count);
     $api = new Latests();
     $result = $api->exec();
     //
     $this->assertTrue(is_array($result));
     $this->assertEquals(2, sizeof($result));
     // check order
     $this->assertEquals(3, $result[0]['id']);
     $this->assertEquals('third', $result[0]['hash']);
     $this->assertEquals(2, $result[1]['id']);
     $this->assertEquals('second', $result[1]['hash']);
 }
Exemplo n.º 18
0
 /**
  * @param $szContent
  * @param $aVariables
  *
  * @return string
  * @throws \Exception
  */
 public static function parsePHPCode($szContent, $viewVariables = null)
 {
     self::callEvent('UParser::before_parse_code', $szContent, $viewVariables);
     try {
         $baseDir = Configure::read('UParser.tmp_dir');
     } catch (ConfigureException $e) {
         throw new \Exception('Directive "UParser.tmp_dir" not defined ');
     }
     $szOld = ob_get_contents();
     ob_clean();
     $__szPath = $baseDir . uniqid();
     file_put_contents($__szPath, $szContent);
     if (!empty($viewVariables)) {
         extract($viewVariables);
     }
     include $__szPath;
     unlink($__szPath);
     $szContent = ob_get_contents();
     ob_clean();
     print $szOld;
     self::callEvent('UParser::after_parse_code', $szContent, $viewVariables, $szContent);
     return $szContent;
 }
Exemplo n.º 19
0
 /**
  * @return \Faid\Cache\Engine\CacheEngineInterface
  */
 protected static function factoryInstance()
 {
     $engineClass = Configure::read(self::ConfigurePath . '.Engine');
     self::$instance = new $engineClass();
 }
Exemplo n.º 20
0
<?php

use Faid\Dispatcher\Dispatcher;
use Extasy\Request;
use Extasy\CMS;
use Faid\Configure\Configure;
$_SERVER['TESTS'] = true;
// Установка времени (необходимо с PHP 5.3)
date_default_timezone_set('Europe/Madrid');
require_once dirname(__FILE__) . '/../src/bootstrap.php';
Configure::write('Debug', true);
// PHPUnit tries to backup global variables during testing
// But PHP not allows to serialize closure functions, exception raises
// So any global variable with closure inside will crash PHPUnit
$dispatcher = null;
include __DIR__ . '/../bootstrap_samples/test-environment.php';
$request = new Request();
$dispatcher = new Dispatcher($request);
new CMS($dispatcher, 'tests');
// phpunit tries to serialize global variables
// $dispatcher could contain closures, so this global variable will break PHPUnit
$dispatcher = null;
Exemplo n.º 21
0
 public function testPrefixesSupported()
 {
     $key = 'test';
     $fixtureA = 'Hello';
     $fixtureB = 'World!';
     $configA = $this->config;
     $configA['prefix'] = 'a';
     $configB = $this->config;
     $configB['prefix'] = 'b';
     //
     Configure::write(Memcache::ConfigurePath, $configA);
     $instance = new Memcache();
     $instance->set($key, $fixtureA);
     Configure::write(Memcache::ConfigurePath, $configB);
     $instance = new Memcache();
     $instance->set($key, $fixtureB);
     //
     Configure::write(Memcache::ConfigurePath, $configA);
     $instance = new Memcache();
     $this->assertEquals($instance->get($key), $fixtureA);
     //
     Configure::write(Memcache::ConfigurePath, $configB);
     $instance = new Memcache();
     $this->assertEquals($instance->get($key), $fixtureB);
     $this->AssertTrue($instance->isActual($key));
     $instance->clear($key);
     $this->AssertFalse($instance->isActual($key));
     Configure::write(Memcache::ConfigurePath, $configA);
     $instance = new Memcache();
     $this->assertEquals($instance->get($key), $fixtureA);
     $this->AssertTrue($instance->isActual($key));
     $instance->clear($key);
     $this->AssertFalse($instance->isActual($key));
 }
Exemplo n.º 22
0
<?php

use Faid\Configure\Configure;
require_once 'vendor/autoload.php';
$db = array('host' => 'localhost', 'socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', 'user' => 'extasy', 'password' => '', 'database' => 'extasy');
$cacheConfig = array('Engine' => '\\Faid\\Cache\\Engine\\FileCache', 'FileCache' => array('BaseDir' => __DIR__ . '/runtime/'));
Configure::write('DB', $db);
Configure::write('SimpleCache', $cacheConfig);
Exemplo n.º 23
0
 public static function getFieldsInfo()
 {
     return \Faid\Configure\Configure::read(static::ModelConfigureKey);
 }
Exemplo n.º 24
0
 protected static function setEventListeners()
 {
     Configure::addEventListener('Configure.write', array('\\Faid\\Debug\\Debug', 'onConfigureWrite'));
 }
Exemplo n.º 25
0
<?php

use Faid\Configure\Configure;
if ($_SERVER['argc'] > 0) {
    define('CLI_MODE', true);
}
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/baseTest.php';
Configure::write('Debug', true);
Configure::write('Error.Handler', function ($errno, $errstr, $errfile = '', $errline = '') {
    var_dump($errno);
    var_dump($errstr);
    var_dump($errfile);
    var_dump($errline);
    printf('%s[ %d ] %d: %s', $errfile, $errline, $errno, $errstr);
    die;
});
Configure::write('Exception.Handler', function ($e) {
    var_dump($e);
    die;
});
Configure::write('FatalError.Handler', function ($message, $file, $line) {
    $error = sprintf('FAID: Fatal error catched "%s"  at : "%s:%d"', $message, $file, $line);
    print $error;
    die;
});
Exemplo n.º 26
0
 /**
  *
  */
 protected function getInitialCookies()
 {
     return sprintf(".%s\tTRUE\t/\tFALSE\t%d\t%s\t%s", \Faid\Configure\Configure::read('MainDomain'), time() + 3600, CMS::UnitTestCookieName, CMS::getUnitTestCookie());
 }
Exemplo n.º 27
0
 public function testSetAndEditArrays()
 {
     $data = array('item1' => 1, 'item2' => 2, 'item3' => 3, 'level2' => array('subitem' => 3, 'sublevel' => array(1, 2, 3)));
     Configure::write('test', $data);
     $this->assertEquals($data['level2'], Configure::read('test.level2'));
 }
Exemplo n.º 28
0
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';
\Faid\Configure\Configure::write('UParser.tmp_dir', dirname(__DIR__) . '/runtime/');
Exemplo n.º 29
0
 /**
  * @expectedException \Faid\NotFoundException
  */
 public function testAutoStartWithEmptyConfig()
 {
     Configure::write(FileStorage::ConfigureKey . '.EnineConfigs', array());
     Configure::write(FileStorage::ConfigureKey . '.default', NULL);
     FileStorage::checkInstance();
 }
Exemplo n.º 30
0
 public function __construct($accessToken = null)
 {
     $this->config = \Faid\Configure\Configure::read(self::ConfigureKey);
     $this->config['redirect_url'] = sprintf('http://%s/oauth/vkontakte/', \Extasy\CMS::getMainDomain());
     $this->token = $accessToken;
 }