Example #1
0
 public function setUp()
 {
     $cache_settings = Ak::getSettings('caching', false);
     $cache_settings['handler']['type'] = 3;
     $this->memcache = AkCache::lookupStore($cache_settings);
     $this->assertIsA($this->memcache, 'AkCache');
 }
 public function index()
 {
     $this->base_dir = AK_BASE_DIR;
     $this->akelos_dir = AK_FRAMEWORK_DIR;
     $this->tasks_dir = AK_TASKS_DIR;
     $this->has_configuration = file_exists(AkConfig::getDir('config') . DS . 'config.php');
     $this->has_routes = file_exists(AkConfig::getDir('config') . DS . 'routes.php');
     $this->has_database = file_exists(AkConfig::getDir('config') . DS . 'database.yml');
     $this->using_root_path = $this->Request->getPath() == '/';
     $this->new_install = !$this->has_configuration || !$this->has_routes || $this->using_root_path;
     $this->environment = AK_ENVIRONMENT;
     $this->memcached_on = AkMemcache::isServerUp();
     $this->constants = AkDebug::get_constants();
     $this->langs = Ak::langs();
     $this->database_settings = Ak::getSettings('database', false);
     $this->server_user = trim(AK_WIN ? `ECHO %USERNAME%` : `whoami`);
     $this->local_ips = AkConfig::getOption('local_ips', array('localhost', '127.0.0.1', '::1'));
     $paths = array(AK_APP_DIR . DS . 'locales');
     $this->invalid_permissions = array();
     foreach ($paths as $path) {
         if (is_dir($path) && !@file_put_contents($path . DS . '__test_file')) {
             $this->invalid_permissions[] = $path;
         } else {
             @unlink($path . DS . '__test_file');
         }
     }
 }
Example #3
0
 public function _flushCache($host)
 {
     $settings = Ak::getSettings('caching',false);
     $fileCache=AkCache::lookupStore($settings);
     if ($fileCache!==false) {
         $fileCache->clean($host);
     }
 }
Example #4
0
 function _perform_logout($redirect = true)
 {
     $this->Sentinel->init($this);
     $this->Sentinel->unsetCurrentUser();
     if ($redirect) {
         $settings = Ak::getSettings('admin');
         $this->redirectTo(empty($settings['sign_in_url']) ? array('action' => 'sign_in') : $settings['sign_in_url']);
     }
 }
Example #5
0
 function setDefaultRole()
 {
     $settings = Ak::getSettings('admin');
     if (!empty($settings['account_settings']['default_role'])) {
         $this->role->load();
         $Role = new Role();
         if ($DefaultRole = $Role->findFirstBy('name', $settings['account_settings']['default_role'])) {
             $this->role->set($DefaultRole);
         }
     }
 }
Example #6
0
 public function _getDefaultOptions($type = 'admin')
 {
     if (!empty($this->_controller->{"default_{$type}_menu_options"})) {
         return $this->_controller->{"default_{$type}_menu_options"};
     } elseif (!empty($this->_controller->{"_{$type}_menu_options"})) {
         return $this->_controller->{"_{$type}_menu_options"};
     } elseif (($options = Ak::getSettings($this->_controller->getModuleName() . "_{$type}_menu", false)) && !empty($options)) {
         return $options;
     } else {
         return $this->_getMenuOptionsForControllersInModule($type);
     }
 }
Example #7
0
 private function _getSettings($settings = null)
 {
     if (is_string($settings)) {
         $this->_useCustomNamespace($settings);
     }
     $settings = !is_array($settings) ? Ak::getSettings($this->settings_namespace, false) : $settings;
     if (empty($settings)) {
         trigger_error(Ak::t('You must provide a connection settings array or create a config/%namespace.yml based on config/sample/object_database.yml', array('%namespace' => $this->settings_namespace)), E_USER_WARNING);
         return false;
     }
     return $settings;
 }
Example #8
0
 static function loadConfig($dictionary)
 {
     static $_loaded = array();
     if (!($return = Ak::getStaticVar('AkInflectorConfig::' . $dictionary))) {
         $return = Ak::getSettings($dictionary, false);
         if ($return !== false) {
             Ak::setStaticVar('AkInflectorConfig::' . $dictionary, $return);
             $_loaded[$dictionary] = true;
         } else {
             trigger_error(Ak::t('Could not load inflector rules file: %file', array('%file' => 'config' . DS . $dictionary . '.yml')), E_USER_ERROR);
         }
     }
     return $return;
 }
Example #9
0
 /**
  * @static
  * @param array $database_settings
  * @return AkDbAdapter
  */
 static function &getInstance($database_specifications = AK_DEFAULT_DATABASE_PROFILE, $auto_connect = true, $namespace = null)
 {
     $settings_hash = is_string($database_specifications) ? $database_specifications : AkDbAdapter::hash($database_specifications);
     $static_var_name = 'AkDbAdapter_getInstance_' . $settings_hash;
     if (!($Connection = Ak::getStaticVar($static_var_name))) {
         defined('AK_DATABASE_SETTINGS_NAMESPACE') || define('AK_DATABASE_SETTINGS_NAMESPACE', 'database');
         $namespace = empty($namespace) ? AK_DATABASE_SETTINGS_NAMESPACE : $namespace;
         if (empty($database_specifications)) {
             $database_specifications = Ak::getSettings($namespace, false, $settings_hash);
         } elseif (is_string($database_specifications)) {
             $environment_settings = Ak::getSettings($namespace, false, $database_specifications);
             if (!empty($environment_settings)) {
                 $database_specifications = $environment_settings;
             } elseif (strstr($database_specifications, '://')) {
                 $database_specifications = AkDbAdapter::getDbSettingsFromDsn($database_specifications);
                 $settings_hash = AK_ENVIRONMENT;
             } else {
                 global $database_settings;
                 if (isset($database_settings) && !file_exists(AkConfig::getDir('config') . DS . $namespace . '.yml')) {
                     trigger_error(Ak::t("You are still using the old config/config.php database configuration. Please upgrade to use the config/database.yml configuration."), E_USER_NOTICE);
                 }
                 if (!file_exists(AkConfig::getDir('config') . DS . $namespace . '.yml')) {
                     trigger_error(Ak::t("Could not find the database configuration file in %dbconfig.", array('%dbconfig' => AkConfig::getDir('config') . DS . $namespace . '.yml')), E_USER_ERROR);
                 } else {
                     trigger_error(Ak::t("Could not find the database profile '%profile_name' in config/%dbfile.yml.", array('%profile_name' => $database_specifications, '%dbfile' => $namespace)), E_USER_ERROR);
                 }
                 $return = false;
                 return $return;
             }
         } elseif (!empty($database_settings[$settings_hash])) {
             $database_specifications = $database_settings[$settings_hash];
         }
         if (empty($database_specifications)) {
             trigger_error(Ak::t('Could not find database settings for %namespace.yml/%settings_hash', array('%namespace' => $namespace, '%settings_hash' => $settings_hash)), E_USER_ERROR);
         }
         // Compatibility with RoR database.yml format
         $database_specifications['user'] = isset($database_specifications['user']) ? $database_specifications['user'] : (isset($database_specifications['username']) ? $database_specifications['username'] : '');
         $database_specifications['type'] = isset($database_specifications['type']) ? $database_specifications['type'] : $database_specifications['adapter'];
         $database_specifications['database_name'] = isset($database_specifications['database_name']) ? $database_specifications['database_name'] : (isset($database_specifications['database']) ? $database_specifications['database'] : '');
         $class_name = 'Ak' . AkInflector::camelize($database_specifications['type']) . 'DbAdapter';
         $adapter_class_file = AK_ACTIVE_RECORD_DIR . DS . 'adapters' . DS . AkInflector::underscore($database_specifications['type']) . '.php';
         if (!@(include_once $adapter_class_file)) {
             trigger_error(Ak::t('Could not find database adapter file on %path', array('%path' => $adapter_class_file)), E_USER_ERROR);
         }
         $Connection = new $class_name($database_specifications, $auto_connect);
         Ak::setStaticVar($static_var_name, $Connection);
     }
     return $Connection;
 }
Example #10
0
 /**
  * @static
  * @param array $database_settings
  * @return AkDbAdapter
  */
 public static function &getInstance($database_specifications = AK_DEFAULT_DATABASE_PROFILE, $auto_connect = true)
 {
     static $connections;
     $settings_hash = is_string($database_specifications) ? $database_specifications : AkDbAdapter::_hash($database_specifications);
     if (empty($connections[$settings_hash])) {
         if (empty($database_specifications)) {
             $settings_hash = AK_ENVIRONMENT;
             $database_specifications = Ak::getSettings('database', false, $settings_hash);
         } else {
             if (is_string($database_specifications)) {
                 $environment_settings = Ak::getSettings('database', false, $database_specifications);
                 if (!empty($environment_settings)) {
                     $database_specifications = $environment_settings;
                 } elseif (strstr($database_specifications, '://')) {
                     $database_specifications = AkDbAdapter::_getDbSettingsFromDsn($database_specifications);
                     $settings_hash = AK_ENVIRONMENT;
                 } else {
                     global $database_settings;
                     if (isset($database_settings) && !file_exists(AK_CONFIG_DIR . DS . 'database.yml')) {
                         trigger_error(Ak::t("You are still using the old config/config.php database configuration. Please upgrade to use the config/database.yml configuration."), E_USER_NOTICE);
                     }
                     if (!file_exists(AK_CONFIG_DIR . DS . 'database.yml')) {
                         trigger_error(Ak::t("Could not find the database configuration file in %dbconfig.", array('%dbconfig' => AK_CONFIG_DIR . DS . 'database.yml')), E_USER_ERROR);
                     } else {
                         trigger_error(Ak::t("Could not find the database profile '%profile_name' in config/database.yml.", array('%profile_name' => $database_specifications)), E_USER_ERROR);
                     }
                     $return = false;
                     return $return;
                 }
             } elseif (!empty($database_settings[$settings_hash])) {
                 $database_specifications = $database_settings[$settings_hash];
             }
         }
         $available_adapters = Ak::toArray(AK_AVAILABLE_DATABASES);
         $class_name = 'AkDbAdapter';
         $designated_database = strtolower($database_specifications['type']);
         if (in_array($designated_database, $available_adapters)) {
             $class_name = 'Ak' . ucfirst($designated_database) . 'DbAdapter';
             require_once AK_LIB_DIR . DS . 'AkActiveRecord' . DS . 'AkDbAdapters' . DS . $class_name . '.php';
         }
         $connections[$settings_hash] = new $class_name($database_specifications, $auto_connect);
     }
     return $connections[$settings_hash];
 }
Example #11
0
 public function dispatchCached()
 {
     $cache_settings = Ak::getSettings('caching', false);
     if ($cache_settings['enabled']) {
         $null = null;
         $pageCache = new AkCacheHandler();
         $pageCache->init($null, $cache_settings);
         if (isset($_GET['allow_get'])) {
             $options['include_get_parameters'] = explode(',', $_GET['allow_get']);
         }
         if (isset($_GET['use_if_modified_since'])) {
             $options['use_if_modified_since'] = true;
         }
         if (($cachedPage = $pageCache->getCachedPage()) !== false) {
             return $cachedPage->render();
         }
     }
     return false;
 }
Example #12
0
 public function init($options){
     # Ak::getLogger('sessions')->info(__METHOD__);
     if($settings=Ak::getSettings('session',false)) {
         $this->options = array_merge($this->default_options, !empty($settings['options'])?$settings['options']:array());
     } else {
         $this->options = $this->default_options;
     }
     $this->options = array_merge($this->options, $options);
     $this->options['expire_after'] = time()+$this->options['expire_after'];
     $this->ensureSessionKey();
     $this->ensureSecretSecure();
     ini_set('session.use_cookies','0');
     session_set_save_handler(
     array($this, 'open'),
     array($this, 'close'),
     array($this, 'read'),
     array($this, 'write'),
     array($this, 'destroy'),
     array($this, 'gc')
     );
     session_start();
     return true;
 }
Example #13
0
 function _initCacheHandler() 
 { 
     // TODOARNO
     $cache_settings = Ak::getSettings('caching', false);
     if ($cache_settings['enabled']) {
         $null = null;
         require_once(AK_LIB_DIR . DS . 'AkActionController' . DS . 'AkCacheHandler.php');
         $this->_CacheHandler =& Ak::singleton('AkCacheHandler', $null);
         $this->_CacheHandler->init(&$this);
     }
 }
Example #14
0
 /**
  * Filters. Public methods but underscored to they cant be triggered directly via URL calls
  */
 public function _loadAdminSettings()
 {
     $this->admin_settings = Ak::getSettings('admin');
     return true;
 }
Example #15
0
 function shouldDefaultToPostAuthentication()
 {
     $settings = Ak::getSettings('admin');
     if (!empty($settings['default_authentication_method']) && $settings['default_authentication_method'] == 'post') {
         return $this->isWebBrowser();
     }
 }
Example #16
0
File: Ak.php Project: joeymetal/v1
 function getSetting($namespace, $variable, $default_value = null)
 {
     if ($settings = Ak::getSettings($namespace)) {
         return isset($settings[$variable]) ? $settings[$variable] : $default_value;
     }
     return $default_value;
 }
Example #17
0
 public function loadSettings()
 {
     if ($settings = Ak::getSettings('mailer', false)) {
         foreach ($settings as $k => $v) {
             $this->{$k} = $v;
         }
     }
 }
Example #18
0
<?php

$default_options = array('mysqldump' => trim(`which mysqldump`), 'dest' => AK_BASE_DIR . DS . 'db' . DS . AK_ENVIRONMENT . '.sql', 'gzip' => trim(`which gzip`), 'compress' => false);
$options = array_merge($default_options, $options);
if (empty($options['mysqldump'])) {
    die("Could not find mysqldump binary.\nPlease try setting the path with ./makelos db:backup mysqldump=/path/to/mysqldump\n");
}
echo "\nPerforming backup of DB schema to {$options['dest']}\n";
$db = Ak::db();
$database_settings = Ak::getSettings('database');
$command = "{$options['mysqldump']} --hex-blob --add-drop-table --single-transaction --skip-comments -u {$database_settings['user']} " . (empty($database_settings['password']) ? '' : "-p{$database_settings['password']} ") . "{$database_settings['database_name']}";
Ak::file_put_contents($options['dest'], ' ');
// touch to create dirs if needed
echo "Running: {$command} > {$options['dest']}\n";
`{$command} > {$options['dest']};`;
echo `du -h {$options['dest']}`;
if ($options['compress'] && !empty($options['gzip'])) {
    echo "\nCompressing backup {$options['gzip']} -f {$options['dest']};\n";
    `{$options['gzip']} -f {$options['dest']};`;
    echo `du -h {$options['dest']}.gz`;
}
Example #19
0
 static function &getInstance(AkActionController &$Controller)
 {
     if (!($CacheHandler = Ak::getStaticVar('AkCacheHandlerSingleton'))) {
         $settings = Ak::getSettings('caching', false);
         if (!empty($settings['enabled'])) {
             $CacheHandler = new AkCacheHandler();
             $CacheHandler->init($Controller);
             Ak::setStaticVar('AkCacheHandlerSingleton', $CacheHandler);
         }
     }
     return $CacheHandler;
 }
Example #20
0
 public function getSignInUrl()
 {
     $settings = Ak::getSettings('admin');
     return $this->urlFor($settings['sign_in_url']);
 }
Example #21
0
 function load_settings()
 {
     $this->admin_settings = Ak::getSettings('admin');
     return true;
 }
Example #22
0
define('AK_DEBUG', 0);
define('AK_SESSION_HANDLER', 1);
if (isset($_GET['expire'])) {
    define('AK_SESSION_EXPIRE', (int) $_GET['expire']);
}
define('AK_ENVIRONMENT', 'testing');
defined('AK_TEST_DIR') ? null : define('AK_TEST_DIR', str_replace(DIRECTORY_SEPARATOR . 'mocks' . DIRECTORY_SEPARATOR . 'test_script_AkDbSession.php', '', __FILE__));
defined('AK_APP_DIR') ? null : define('AK_APP_DIR', AK_TEST_DIR . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'app');
define('AK_SITE_URL_SUFFIX', str_replace(array(join(DIRECTORY_SEPARATOR, array_diff((array) @explode(DIRECTORY_SEPARATOR, AK_TEST_DIR), (array) @explode('/', @$_SERVER['REQUEST_URI']))), DIRECTORY_SEPARATOR), array('', '/'), AK_TEST_DIR));
include '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
require_once AK_LIB_DIR . DS . 'Ak.php';
require_once AK_LIB_DIR . DS . 'AkInflector.php';
Ak::db();
require_once AK_LIB_DIR . DS . 'AkSession.php';
$session_handler = isset($_GET['handler']) ? $_GET['handler'] : null;
$session_settings = Ak::getSettings('sessions', false);
if ($session_handler !== null) {
    $session_settings['handler']['type'] = (int) $session_handler;
}
$SessionHandler = AkSession::lookupStore($session_settings);
session_start();
if (isset($_GET['key']) && isset($_GET['value'])) {
    $_SESSION[$_GET['key']] = $_GET['value'];
} elseif (isset($_GET['key'])) {
    if (isset($_SESSION[$_GET['key']])) {
        echo $_SESSION[$_GET['key']];
    } else {
        echo 'value not found';
    }
}
if (isset($_GET['unset'])) {
Example #23
0
 static function initHandler()
 {
     $settings = Ak::getSettings('sessions', false);
     return AkSession::lookupStore($settings);
 }
Example #24
0
 function initHandler()
 {
     $settings = Ak::getSettings('sessions', false);
     $SessionHandler = &AkSession::lookupStore($settings);
     return $SessionHandler;
 }
Example #25
0
<?php

//define('AK_HOST','localhost');
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$host = AK_HOST;
require_once AK_LIB_DIR . DS . 'Ak.php';
$cache_settings = Ak::getSettings('caching', false);
if ($cache_settings['enabled']) {
    require_once AK_LIB_DIR . DS . 'AkActionController' . DS . 'AkCacheHandler.php';
    $null = null;
    $pageCache =& Ak::singleton('AkCacheHandler', $null);
    $pageCache->init($null, $cache_settings);
    if (isset($_GET['allow_get'])) {
        $options['include_get_parameters'] = split(',', $_GET['allow_get']);
    }
    if (isset($_GET['use_if_modified_since'])) {
        $options['use_if_modified_since'] = true;
    }
    if (($cachedPage = $pageCache->getCachedPage()) !== false) {
        $cachedPage->render();
    }
}
require_once AK_LIB_DIR . DS . 'AkDispatcher.php';
$Dispatcher =& new AkDispatcher();
$Dispatcher->dispatch();
Example #26
0
 function _init($url, $constants = array(), $controllerVars = array())
 {
     $this->_reset();
     $this->_response = null;
     $this->_cacheHeaders = array();
     $this->_setConstants($constants);
     $parts = parse_url($url);
     $_REQUEST['ak'] = isset($parts['path']) ? $parts['path'] : '/';
     $_SERVER['AK_HOST'] = isset($parts['host']) ? $parts['host'] : 'localhost';
     $cache_settings = Ak::getSettings('caching', false);
     if ($cache_settings['enabled']) {
         require_once AK_LIB_DIR . DS . 'AkActionController' . DS . 'AkCacheHandler.php';
         $null = null;
         $pageCache =& Ak::singleton('AkCacheHandler', $null);
         $pageCache->init($null, $cache_settings);
         if ($cachedPage = $pageCache->getCachedPage()) {
             static $_cachedHeaders = array();
             ob_start();
             global $sendHeaders, $returnHeaders, $exit;
             $sendHeaders = false;
             $returnHeaders = true;
             $exit = false;
             $headers = (include $cachedPage);
             //$headers = $cachedPage->render(false,false,true);
             $this->_response = ob_get_clean();
             if (is_array($headers)) {
                 $this->_cacheHeaders = $headers;
             }
             return true;
         }
     }
     require_once AK_LIB_DIR . DS . 'AkUnitTest' . DS . 'AkTestDispatcher.php';
     $this->Dispatcher =& new AkTestDispatcher($controllerVars);
 }
Example #27
0
 function getSignInUrl()
 {
     $settings = Ak::getSettings('admin');
     $settings['base_url'] = isset($settings['base_url']) ? $settings['base_url'] : true;
     return $this->urlFor($settings['sign_in_url']);
 }
Example #28
0
 function _loadSettings($settings = null)
 {
     if ($settings == null) {
         $this->_settings = Ak::getSettings('caching', false);
     } else if (is_array($settings)) {
         $this->_settings = $settings;
     } else {
         return;
     }
     $this->_setCacheStore($this->_settings);
 }
Example #29
0
 /**
  * ########################################################################
  * #
  * #               Modules
  * #
  * ########################################################################
  */
 public function _initCacheHandler()
 {
     // TODOARNO
     $cache_settings = Ak::getSettings('caching', false);
     if ($cache_settings['enabled']) {
         $null = null;
         $this->_CacheHandler = Ak::singleton('AkCacheHandler', $null);
         $this->_CacheHandler->init($this);
     }
 }