示例#1
0
 static function updateCacheFileAfterExecution($environment = null)
 {
     static $called = false, $_environment;
     if ($called == false && !AkDbSchemaCache::shouldRefresh()) {
         register_shutdown_function(array('AkDbSchemaCache', 'updateCacheFileAfterExecution'));
         $called = !empty($environment) ? $environment : AK_ENVIRONMENT;
     } elseif (empty($environment)) {
         $config = AkDbSchemaCache::config(null, null, $called);
         $file_name = AkDbSchemaCache::getCacheFileName($called);
         /**
          * @todo On PHP5 var_export requires objects that implement the __set_state magic method.
          *       As see on stangelanda at arrowquick dot benchmarks at comhttp://php.net/var_export
          *       serialize works faster without opcode caches. We should do our benchmarks with
          *       var_export VS serialize using APC once we fix the __set_state magic on phpAdoDB
          */
         if (AK_LOG_EVENTS) {
             $Logger = Ak::getLogger();
         }
         if (!AK_CLI) {
             if (AK_LOG_EVENTS) {
                 $Logger->message('Updating database settings on ' . $file_name);
             }
             AkFileSystem::file_put_contents($file_name, serialize($config), array('base_path' => AK_TMP_DIR));
             //file_put_contents($file_name, serialize($config));
         } else {
             if (AK_LOG_EVENTS) {
                 $Logger->message('Skipping writing of cache file: ' . $file_name);
             }
         }
     }
 }
示例#2
0
 public function test_should_generate_controller_and_auxiliary_files()
 {
     $files = array(AkConfig::getDir('controllers') . DS . 'credit_card_controller.php', AkConfig::getDir('helpers') . DS . 'credit_card_helper.php', AkConfig::getDir('test') . DS . 'functional' . DS . 'controllers' . DS . 'credit_card_controller_test.php', AkConfig::getDir('test') . DS . 'unit' . DS . 'helpers' . DS . 'credit_card_helper_test.php', AkConfig::getDir('views') . DS . 'credit_card' . DS . 'open.html.tpl', AkConfig::getDir('views') . DS . 'credit_card' . DS . 'debit.html.tpl', AkConfig::getDir('views') . DS . 'credit_card' . DS . 'credit.html.tpl', AkConfig::getDir('views') . DS . 'credit_card' . DS . 'close.html.tpl');
     clearstatcache();
     foreach ($files as $file) {
         file_exists($file) && unlink($file);
         $this->assertFalse(file_exists($file));
     }
     AkFileSystem::file_put_contents(AkConfig::getDir('views') . DS . 'credit_card' . DS . 'credit.html.tpl', 'foo', array('base_path' => AK_FRAMEWORK_DIR));
     clearstatcache();
     $this->assertPattern('/collisions/', $this->runGeneratorCommand('controller CreditCard open debit credit close'));
     AkFileSystem::file_delete(AkConfig::getDir('views') . DS . 'credit_card' . DS . 'credit.html.tpl', array('base_path' => AK_FRAMEWORK_DIR));
     clearstatcache();
     foreach ($files as $file) {
         $this->assertFalse(file_exists($file));
     }
     $this->assertPattern('/ files have been created/', $this->runGeneratorCommand('controller CreditCard open debit credit close'));
     clearstatcache();
     foreach ($files as $file) {
         $this->assertTrue(file_exists($file));
         if (!file_exists($file)) {
             AkDebug::trace($file);
         }
         @unlink($file);
     }
 }
示例#3
0
 public function test_should_fill_the_table_with_yaml_data()
 {
     $unit_tester = new AkUnitTest();
     $unit_tester->installAndIncludeModels(array('TheModel' => 'id,name'));
     $TheModel =& $unit_tester->TheModel;
     $TheModel->create(array('name' => 'eins'));
     $TheModel->create(array('name' => 'zwei'));
     $TheModel->create(array('name' => 'drei'));
     $TheModel->create(array('name' => 'vier'));
     $this->assertEqual($TheModel->count(), 4);
     $this->assertTrue($AllRecords = $TheModel->find());
     $yaml = $TheModel->toYaml($AllRecords);
     $yaml_path = AkConfig::getDir('fixtures') . DS . 'the_models.yml';
     $this->assertFalse(file_exists($yaml_path));
     AkFileSystem::file_put_contents($yaml_path, $yaml);
     $unit_tester->installAndIncludeModels(array('TheModel' => 'id,name'));
     try {
         $TheModel->find();
     } catch (RecordNotFoundException $e) {
         $this->pass();
     }
     $this->assertEqual($TheModel->count(), 0);
     $unit_tester->installAndIncludeModels(array('TheModel' => 'id,name'), array('populate' => true));
     $this->assertEqual($TheModel->count(), 4);
     unlink($yaml_path);
 }
示例#4
0
文件: profiler.php 项目: bermi/akelos
 public function saveReport()
 {
     if ($this->report == '') {
         $this->renderReport();
     }
     AkFileSystem::file_put_contents('profiler_results.txt', $this->report);
 }
示例#5
0
 public function test_should_get_all_controllers_with_their_actions()
 {
     $available_controllers = (array) AkFileSystem::dir(AkConfig::getDir('controllers'), array('dirs' => false));
     $got = $this->menu_helper->_get_default_full_menu();
     foreach ($available_controllers as $controller_filename) {
         $controller_name = str_replace('_controller.php', '', $controller_filename);
         $this->assertTrue(isset($got[$controller_name]));
     }
     $this->assertTrue(in_array('authenticate', $got['authentication']));
 }
示例#6
0
 public function _get_file_details($key)
 {
     $key = preg_replace('/[^A-Z^a-z^0-9]/', '', $key);
     $file = $this->get_persisted_file($key);
     if (!empty($file)) {
         AkFileSystem::file_put_contents($this->_getTempDir() . DS . '_file_uploader_file_' . $key, base64_decode($file['contents']), array('ftp' => false));
         return array('tmp_name' => $this->_getTempDir() . DS . '_file_uploader_file_' . $key, 'size' => $file['size'], 'name' => $file['name'], 'type' => $file['type'], 'error' => 0);
     } else {
         return false;
     }
 }
示例#7
0
 public function __construct($options)
 {
     $default_options = array('source' => $this->getAbsolutePath(dirname(__FILE__) . DIRECTORY_SEPARATOR . str_repeat(DIRECTORY_SEPARATOR . '..', 4) . DIRECTORY_SEPARATOR . 'app_layout'), 'force' => false, 'skip' => false, 'quiet' => false, 'public_html' => false);
     $this->options = array_merge($default_options, $options);
     $this->options['directory'] = $this->getAbsolutePath(@$this->options['directory']);
     if (empty($this->options['directory'])) {
         trigger_error('You must supply a valid destination path', E_USER_ERROR);
     }
     $this->source_tree = AkFileSystem::dir($this->options['source'], array('dirs' => true, 'recurse' => true));
     $this->destination_tree = AkFileSystem::dir($this->options['directory'], array('dirs' => true, 'recurse' => true));
 }
示例#8
0
文件: config.php 项目: bermi/akelos
 public function tearDown()
 {
     AkFileSystem::file_delete($this->_base_config_path . DS . 'testing' . DS . 'testconfig1.php', array('base_path' => $this->_base_config_path));
     AkFileSystem::file_delete($this->_base_config_path . DS . 'development' . DS . 'testconfig1.php', array('base_path' => $this->_base_config_path));
     AkFileSystem::file_delete($this->_base_config_path . DS . 'production' . DS . 'testconfig1.php', array('base_path' => $this->_base_config_path));
     AkFileSystem::rmdir_tree($this->_base_config_path . DS . 'testing');
     AkFileSystem::rmdir_tree($this->_base_config_path . DS . 'development');
     AkFileSystem::rmdir_tree($this->_base_config_path . DS . 'production');
     AkFileSystem::file_delete(AkConfig::getDir('config') . DS . 'testconfig1.yml', array('base_path' => $this->_base_config_path));
     AkFileSystem::rmdir_tree($this->_base_config_path);
     AkFileSystem::rmdir_tree(AkConfig::getDir('tmp') . DS . 'ak_config');
 }
示例#9
0
文件: ak.php 项目: bermi/akelos
 public function test_should_get_the_right_temp_dir()
 {
     $tmp_dir = Ak::get_tmp_dir_name();
     $tmp_file = $tmp_dir . DS . 'ak_test_' . __CLASS__;
     $tmp_file2 = $tmp_dir . DS . 'ak_test_dir' . DS . 'level_one' . DS . 'file.txt';
     $this->assertTrue(is_dir($tmp_dir), 'Could not find temporary directory at: ' . $tmp_dir);
     $this->assertTrue(touch($tmp_dir . DS . 'ak_test_' . __CLASS__), 'Can\'t touch files on the temporary directory ' . $tmp_dir);
     $this->assertTrue(AkFileSystem::file_put_contents($tmp_file, 'abc'), 'Can\'t write on the temporary file ' . $tmp_file);
     $this->assertTrue(AkFileSystem::file_get_contents($tmp_file) == 'abc', 'Can\'t write on the temporary file ' . $tmp_file);
     $this->assertTrue(AkFileSystem::file_put_contents($tmp_file2, 'abce'), 'Can\'t write on the temporary file ' . $tmp_file2);
     $this->assertTrue(AkFileSystem::file_get_contents($tmp_file2) == 'abce', 'Can\'t write on the temporary file ' . $tmp_file2);
     $this->assertEqual($tmp_dir, AK_TMP_DIR);
 }
示例#10
0
 public function raiseError($code = null)
 {
     $code = empty($code) ? @$this->_options['code'] : $code;
     if (AK_DEBUG) {
         // We can't halt execution while testing and the error message is too large for trigger_error
         if (AK_ENVIRONMENT == 'testing') {
             trigger_error(join("\n", $this->getErrors()), E_USER_WARNING);
         } else {
             echo '<h1>' . Ak::t('Template %template_file security error', array('%template_file' => @$this->_options['file_path'])) . ':</h1>' . "<ul><li>" . join("</li>\n<li>", $this->getErrors()) . "</li></ul><hr />\n" . '<h2>' . Ak::t('Showing template source from %file:', array('%file' => $this->_options['file_path'])) . '</h2>' . (isset($this->_options['file_path']) ? '<pre>' . htmlentities(AkFileSystem::file_get_contents($this->_options['file_path'])) . '</pre><hr />' : '') . '<h2>' . Ak::t('Showing compiled template source:') . '</h2>' . highlight_string($code, true);
             die;
         }
     } else {
         trigger_error(Ak::t('Template compilation error'), E_USER_ERROR);
     }
 }
示例#11
0
 public function _getMenuOptionsForControllersInModule($type = 'admin')
 {
     $controllers = AkFileSystem::dir(AK_CONTROLLERS_DIR . DS . $this->_controller->getModuleName(), array('dirs' => false));
     sort($controllers);
     $menu_options = array();
     foreach ($controllers as $controller) {
         $controller_name = substr($controller, 0, -15);
         $menu_options[AkInflector::titleize($controller_name)] = array('id' => $controller_name, 'url' => array('controller' => $controller_name));
     }
     $options_file = $this->_getMenuOptionsFile($type);
     if (!file_exists($options_file)) {
         AkFileSystem::file_put_contents(AK_CONFIG_DIR . DS . $options_file, Ak::convert('array', 'yaml', array('default' => $menu_options)));
     }
     return $menu_options;
 }
示例#12
0
 public function generate()
 {
     $this->_preloadPaths();
     $this->save(AkConfig::getDir('app') . DS . $this->controller_path, $this->render('controller'));
     $this->save(AkConfig::getDir('helpers') . DS . $this->underscored_controller_name . "_helper.php", $this->render('helper'));
     $this->save(AkConfig::getDir('test') . DS . 'functional' . DS . $this->controller_test_path, $this->render('functional_test'));
     $this->save(AkConfig::getDir('test') . DS . 'unit' . DS . 'helpers' . DS . $this->underscored_controller_name . "_helper_test.php", $this->render('helper_test'));
     @AkFileSystem::make_dir(AkConfig::getDir('views') . DS . $this->module_path . AkInflector::underscore($this->controller_name), $this->getFileOptions());
     foreach ($this->actions as $action) {
         //$this->action = $action;
         $this->assignVarToTemplate('action', $action);
         $this->assignVarToTemplate('path', 'app' . DS . 'views' . DS . $this->module_path . AkInflector::underscore($this->controller_name) . DS . $action . '.html.tpl');
         $this->save(AkConfig::getDir('views') . DS . $this->module_path . AkInflector::underscore($this->controller_name) . DS . $action . '.html.tpl', $this->render('view'));
     }
 }
示例#13
0
 public function _get_default_full_menu()
 {
     $controllers_dir = AkConfig::getDir('controllers');
     $controller_file_names = array_map('array_pop', (array) AkFileSystem::dir($controllers_dir, array('files' => false)));
     sort($controller_file_names);
     $menu_options = array();
     foreach ($controller_file_names as $controller_file_name) {
         $controller_name = str_replace('.php', '', $controller_file_name);
         if (strstr($controller_file_name, '_controller.php') && file_exists($controllers_dir . DS . $controller_file_name)) {
             include_once $controllers_dir . DS . $controller_file_name;
             $controller_class_name = AkInflector::classify($controller_name);
             $menu_options[str_replace('_controller', '', $controller_name)] = $this->_get_this_class_methods($controller_class_name);
         }
     }
     return $menu_options;
 }
示例#14
0
 function generate()
 {
     $this->_preloadPaths();
     $this->class_name = AkInflector::camelize($this->class_name);
     $files = array('mailer' => AkInflector::toModelFilename($this->class_name), 'unit_test' => AK_TEST_DIR . DS . 'unit' . DS . 'app' . DS . 'models' . DS . $this->underscored_class_name . '.php');
     foreach ($files as $template => $file_path) {
         $this->save($file_path, $this->render($template));
     }
     $mailer_views_folder = AK_VIEWS_DIR . DS . AkInflector::underscore($this->class_name);
     @AkFileSystem::make_dir($mailer_views_folder);
     foreach ($this->actions as $action) {
         $this->assignVarToTemplate('action', $action);
         $path = $mailer_views_folder . DS . $action . '.tpl';
         $this->assignVarToTemplate('path', $path);
         $this->save($path, $this->render('view'));
     }
 }
示例#15
0
 public function init()
 {
     $this->ext = empty($this->ext) ? 'xls' : strtolower(trim($this->ext, '.'));
     $this->tmp_name = Ak::randomString();
     if (empty($this->source_file)) {
         $this->source_file = AK_TMP_DIR . DS . $this->tmp_name . '.' . $this->ext;
         AkFileSystem::file_put_contents($this->source_file, $this->source);
         $this->delete_source_file = true;
         $this->keep_destination_file = empty($this->keep_destination_file) ? empty($this->destination_file) ? false : true : $this->keep_destination_file;
     } else {
         $this->delete_source_file = false;
         $this->keep_destination_file = true;
     }
     $this->convert_to = !empty($this->convert_to) && empty($this->_file_type_codes[$this->convert_to]) ? 'csv' : (empty($this->convert_to) ? 'csv' : $this->convert_to);
     $this->destination_file_name = empty($this->destination_file_name) ? $this->tmp_name . '.' . $this->convert_to : $this->destination_file_name . (strstr($this->destination_file_name, '.') ? '' : '.' . $this->convert_to);
     $this->destination_file = empty($this->destination_file) ? AK_TMP_DIR . DS . $this->destination_file_name : $this->destination_file;
 }
示例#16
0
 public function init()
 {
     if (empty($this->handler)) {
         require_once AK_CONTRIB_DIR . DS . 'Excel' . DS . 'reader.php';
         $this->handler = new Spreadsheet_Excel_Reader();
         $this->handler->setRowColOffset(empty($this->first_column) ? 0 : $this->first_column);
     }
     $this->tmp_name = Ak::randomString();
     if (empty($this->source_file)) {
         $this->source_file = AK_TMP_DIR . DS . $this->tmp_name . '.xls';
         AkFileSystem::file_put_contents($this->source_file, $this->source);
         $this->delete_source_file = true;
         $this->keep_destination_file = empty($this->keep_destination_file) ? empty($this->destination_file) ? false : true : $this->keep_destination_file;
     } else {
         $this->delete_source_file = false;
         $this->keep_destination_file = true;
     }
 }
示例#17
0
    public function relativizeStylesheetPaths()
    {
        $url_suffix = AkConsole::promptUserVar('The admin plugin comes with some fancy CSS background images.

Your application might be accessible at /myapp, 
and your images folder might be at /myapp/public

Insert the relative path where your images folder is
so you don\'t need to manually edit the CSS files', array('default' => '/'));
        $url_suffix = trim(preg_replace('/\\/?images\\/admin\\/?$/', '', $url_suffix), '/');
        if (!empty($url_suffix)) {
            $stylesheets = array('admin/admin', 'admin/menu');
            foreach ($stylesheets as $stylesheet) {
                $filename = AK_PUBLIC_DIR . DS . 'stylesheets' . DS . $stylesheet . '.css';
                $relativized_css = preg_replace("/url\\((\\'|\")?\\/images/", "url(\$1/{$url_suffix}/images", @AkFileSystem::file_get_contents($filename));
                !empty($relativized_css) && @AkFileSystem::file_put_contents($filename, $relativized_css);
            }
        }
    }
示例#18
0
 public function test_cleanup()
 {
     @AkFileSystem::file_delete(AkConfig::getDir('models') . DS . 'group_user.php');
 }
示例#19
0
文件: makelos.php 项目: bermi/akelos
 public function runTaskAsDaemon($task_name, $options = array())
 {
     $this->_ensurePosixAndPcntlAreAvailable();
     require_once 'System/Daemon.php';
     $app_name = AkInflector::underscore($task_name);
     $pid_file = AK_BASE_DIR . DS . 'run' . DS . $app_name . DS . $app_name . '.pid';
     $log_file = AK_LOG_DIR . DS . 'daemons' . DS . $app_name . '.log';
     if (!file_exists($pid_file)) {
         if (empty($options['attributes']['kill'])) {
             AkFileSystem::file_put_contents($pid_file, '');
             AkFileSystem::file_delete($pid_file);
         } else {
             $this->error("Could not kill process for {$task_name}", true);
         }
     } else {
         $pid = (int) file_get_contents($pid_file);
         if ($pid > 0) {
             if (!empty($options['attributes']['kill'])) {
                 $this->message("Killing process {$pid}");
                 `kill {$pid}`;
                 AkFileSystem::file_delete($pid_file);
                 die;
             } elseif (!empty($options['attributes']['restart'])) {
                 $this->message("Restarting {$task_name}.");
                 $this->message(`kill {$pid}`);
             } else {
                 $this->error("Daemon for {$task_name} still running ({$pid_file}).\nTask aborted.", true);
             }
         }
     }
     if (!empty($options['attributes']['kill']) && empty($pid)) {
         $this->error("No daemon running for task {$task_name}", true);
     }
     unset($options['attributes']['restart']);
     if (!file_exists($log_file)) {
         AkFileSystem::file_put_contents($log_file, '');
     }
     System_Daemon::setOption('appName', $app_name);
     System_Daemon::setOption('appDir', AK_BASE_DIR);
     System_Daemon::setOption('logLocation', $log_file);
     System_Daemon::setOption('appRunAsUID', posix_geteuid());
     System_Daemon::setOption('appRunAsGID', posix_getgid());
     System_Daemon::setOption('appPidLocation', $pid_file);
     $this->message("Staring daemon. ({$log_file})");
     System_Daemon::start();
     $dsn = Ak::getStaticVar('dsn');
     defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? null : Ak::db($dsn);
     $this->runTask($task_name, $options);
     System_Daemon::stop();
     AkFileSystem::file_delete($pid_file);
     die;
 }
示例#20
0
 public function __destruct()
 {
     if (file_exists($this->_tmp_file)) {
         @AkFileSystem::file_delete($this->_tmp_file);
     }
 }
示例#21
0
文件: parser.php 项目: bermi/akelos
 protected function _getImagePath($path)
 {
     $tmp_dir = AkConfig::getDir('tmp');
     if (preg_match('/^http(s)?:\\/\\//', $path)) {
         $path_info = pathinfo($path);
         $base_file_name = Ak::sanitize_include($path_info['basename'], 'paranaoid');
         if (empty($path_info['extension'])) {
             // no extension, we don't do magic stuff
             $path = '';
         } else {
             $local_path = $tmp_dir . DS . 'mailer' . DS . 'remote_images' . DS . md5($path) . DS . $base_file_name . '.' . $path_info['extension'];
             if (!file_exists($local_path) || time() > filemtime($local_path) + 7200) {
                 if (!AkFileSystem::file_put_contents($local_path, Ak::url_get_contents($path), array('base_path' => $tmp_dir))) {
                     return '';
                 }
             }
             if (!file_exists($local_path) || filesize($local_path) < 1) {
                 return '';
             }
             return $local_path;
         }
     }
     $org_path = $path;
     $public_dir = AkConfig::getDir('public');
     $path = $public_dir . $path;
     $path = realpath($path);
     if (substr($path, 0, strlen($public_dir)) != $public_dir || !file_exists($path)) {
         $path = '';
     }
     return $path;
 }
示例#22
0
 public function test_framework_config_locale_update()
 {
     $langs = Ak::langs();
     $translation_key = Ak::randomString(8);
     $this->assertEqual(Ak::t($translation_key), $translation_key);
     $locale_files = AkLocaleManager::updateLocaleFiles();
     list($locales, $core_dictionary) = AkLocaleManager::getCoreDictionary(AK_FRAMEWORK_LANGUAGE);
     $this->assertTrue(isset($core_dictionary[$translation_key]));
     foreach ($langs as $lang) {
         list($locales, $core_dictionary) = AkLocaleManager::getCoreDictionary($lang);
         $this->assertTrue(isset($core_dictionary[$translation_key]));
     }
     foreach ($locale_files as $locale_file) {
         AkFileSystem::file_delete($locale_file);
     }
 }
示例#23
0
文件: base.php 项目: bermi/akelos
    public function writeCache($config, $namespace, $environment = AK_ENVIRONMENT, $force = false)
    {
        if (!$force && !$this->_useWriteCache($environment)) {
            return false;
        }
        $key = $this->_getCacheKey($namespace, $environment);
        Ak::setStaticVar($key, $config);
        $var_export = var_export($config, true);
        $cache = <<<CACHE
<?php
/**
 * Auto-generated config cache from {$namespace} in environment {$environment}
 */
\$config = {$var_export};
return \$config;

CACHE;
        $cache_file_name = $this->getCacheFileName($namespace, $environment);
        if (!AkFileSystem::file_put_contents($cache_file_name, $cache, array('base_path' => AkConfig::getCacheBasePath()))) {
            trigger_error(Ak::t('Could not create config cache file %file', array('%file' => $cache_file_name)) . ' ' . AkDebug::getFileAndNumberTextForError(1), E_USER_ERROR);
            return false;
        } else {
            return true;
        }
    }
示例#24
0
 static function setDictionary($dictionary, $language, $namespace = false, $comment = null)
 {
     $path = AkConfig::getDir('app') . DS . 'locales' . DS . ($namespace ? trim(Ak::sanitize_include($namespace, 'high'), DS) . DS : '') . basename($language) . '.php';
     AkLocaleManager::getDictionary($language, $namespace, true, $dictionary);
     AkFileSystem::file_put_contents($path, "<?php\n/** {$comment} */\n\n\$dictionary=" . var_export((array) $dictionary, true) . ";\n");
     return $path;
 }
示例#25
0
 /**
  * This method tries to determine if url rewrite is enabled on this server.
  * It has only been tested on apache.
  * It is strongly recomended that you manually define the constant 
  * AK_URL_REWRITE_ENABLED on your config file to the avoid overload
  * this function causes and to prevent from missfunctioning
  */
 static function loadUrlRewriteSettings()
 {
     static $result;
     if (isset($result)) {
         return $result;
     }
     if (defined('AK_URL_REWRITE_ENABLED')) {
         $result = AK_URL_REWRITE_ENABLED;
         return AK_URL_REWRITE_ENABLED;
     }
     if (defined('AK_ENABLE_URL_REWRITE') && AK_ENABLE_URL_REWRITE == false) {
         if (!defined('AK_URL_REWRITE_ENABLED')) {
             define('AK_URL_REWRITE_ENABLED', false);
         }
         $result = AK_URL_REWRITE_ENABLED;
         return false;
     }
     $url_rewrite_status = false;
     //echo '<pre>'.print_r(get_defined_functions(), true).'</pre>';
     if (isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] == 200 && isset($_SERVER['REDIRECT_QUERY_STRING']) && strstr($_SERVER['REDIRECT_QUERY_STRING'], 'ak=')) {
         if (strstr($_SERVER['REDIRECT_QUERY_STRING'], '&')) {
             $tmp_arr = explode('&', $_SERVER['REDIRECT_QUERY_STRING']);
             $ak_request = $tmp_arr[0];
         } else {
             $ak_request = $_SERVER['REDIRECT_QUERY_STRING'];
         }
         $ak_request = trim(str_replace('ak=', '', $ak_request), '/');
         if (strstr($_SERVER['REDIRECT_URL'], $ak_request)) {
             $url_rewrite_status = true;
         } else {
             $url_rewrite_status = false;
         }
     } elseif (function_exists('apache_get_modules')) {
         $available_modules = apache_get_modules();
         if (in_array('mod_rewrite', (array) $available_modules)) {
             // Local session name is changed intentionally from .htaccess
             // So we can see if the file has been loaded.
             // if so, we restore the session.name to its original
             // value
             if (ini_get('session.name') == 'AK_SESSID') {
                 $session_name = defined('AK_SESSION_NAME') ? AK_SESSION_NAME : get_cfg_var('session.name');
                 ini_set('session.name', $session_name);
                 $url_rewrite_status = true;
                 // In some cases where session.name cant be set up by htaccess file,
                 // we can check for modrewrite status on this file
             } elseif (file_exists(AK_BASE_DIR . DS . '.htaccess')) {
                 $htaccess_file = AkFileSystem::file_get_contents(AK_BASE_DIR . DS . '.htaccess');
                 if (stristr($htaccess_file, 'RewriteEngine on')) {
                     $url_rewrite_status = true;
                 }
             }
         }
         // If none of the above works we try to fetch a file that should be remaped
     } elseif (isset($_SERVER['REDIRECT_URL']) && $_SERVER['REDIRECT_URL'] == '/' && isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] == 200) {
         $url_rewrite_test_url = AK_URL . 'mod_rewrite_test';
         if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
             $url_rewrite_test_url = AK_PROTOCOL . $_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW'] . '@' . AK_HOST . '/mod_rewrite_test';
         }
         $url_rewrite_status = strstr(@file_get_contents($url_rewrite_test_url), 'AK_URL_REWRITE_ENABLED');
         $AK_URL_REWRITE_ENABLED = "define(\\'AK_URL_REWRITE_ENABLED\\', " . ($url_rewrite_status ? 'true' : 'false') . ");\n";
         register_shutdown_function(create_function('', "AkFileSystem::file_put_contents(AkConfig::getDir('config').DS.'config.php',\n            str_replace('<?php\n','<?php\n\n{$AK_URL_REWRITE_ENABLED}',AkFileSystem::file_get_contents(AkConfig::getDir('config').DS.'config.php')));"));
     }
     if (!defined('AK_URL_REWRITE_ENABLED')) {
         define('AK_URL_REWRITE_ENABLED', $url_rewrite_status);
     }
     $result = AK_URL_REWRITE_ENABLED;
     return AK_URL_REWRITE_ENABLED;
 }
示例#26
0
文件: composer.php 项目: bermi/akelos
 protected function _getAvailableTemplates()
 {
     $path = $this->ActionMailer->getTemplatePath();
     if (!isset($templates[$path])) {
         $templates[$path] = array_map('basename', AkFileSystem::dir($path, array('dirs' => false)));
     }
     return $templates[$path];
 }
示例#27
0
 public function tearDown()
 {
     foreach (explode(',', 'aa_ee,bb_cc,dd_ee') as $file) {
         @AkFileSystem::file_delete(AkConfig::getDir('models') . DS . $file . '.php');
     }
 }
示例#28
0
 public function absolutizeStaticAssetFilePaths($files_dir, $relative_url = '/')
 {
     if ($relative_url == '/') {
         return;
     }
     $relative_url = str_replace('//', '/', '/' . trim($relative_url, '/') . '/');
     $replacements = array('url(/images' => 'url(' . $relative_url . 'images', 'url(\'/images' => 'url(\'' . $relative_url . 'images', 'url("/images' => 'url("' . $relative_url . 'images', 'src="/images/' => 'src="' . $relative_url . 'images/', 'src=\'/images/' => 'src=\'' . $relative_url . 'images/', 'src="/javascrips/' => 'src="' . $relative_url . 'javascrips/', 'src=\'/javascrips/' => 'src=\'' . $relative_url . 'javascrips/', 'type="text/css" href="/stylesheets' => 'type="text/css" href="' . $relative_url . 'stylesheets', 'type=\'text/css\' href=\'/stylesheets' => 'type=\'text/css\' href=\'' . $relative_url . 'stylesheets');
     $keys = array_keys($replacements);
     $values = array_values($replacements);
     $this->files = AkFileSystem::dir($files_dir, array('recurse' => true));
     empty($this->options['force']) ? $this->_checkForModified($this->files, $files_dir, $files_dir) : null;
     $installed_files = $this->_getInstalledFiles($this->files, $files_dir, $files_dir);
     foreach ($installed_files as $installed_file) {
         if (preg_match('/\\.(js|css|html)$/', $installed_file)) {
             $contents = str_replace($keys, $values, file_get_contents($installed_file));
             file_put_contents($installed_file, $contents);
         }
     }
 }
示例#29
0
 public function test_is_dir()
 {
     if (!RUN_FTP_TESTS) {
         return;
     }
     $path = 'invalid path';
     $this->assertFalse(AkFtp::is_dir($path));
     $path = 'this_is_a_file.txt';
     AkFileSystem::file_put_contents('this_is_a_file.txt', '');
     $this->assertFalse(AkFtp::is_dir($path));
     AkFtp::make_dir('tmp_test_dir');
     AkFileSystem::file_put_contents('tmp_test_dir/file_inside.txt', '');
     $path = 'tmp_test_dir/file_inside.txt';
     $this->assertFalse(AkFtp::is_dir($path));
     AkFtp::make_dir('real_dir/another/dir');
     $path = 'real_dir';
     $this->assertTrue(AkFtp::is_dir($path));
     $path = 'real_dir/another/dir';
     $this->assertTrue(AkFtp::is_dir($path));
     AkFtp::delete('real_dir');
     AkFtp::delete('this_is_a_file.txt');
     AkFtp::delete('tmp_test_dir');
     AkFtp::delete('cache');
 }
示例#30
0
文件: base.php 项目: bermi/akelos
 /**
  * Loads a list of existing plugins to $this->_available_plugins by inspecting the plugins directory.
  * 
  * @return void   
  * @access private
  */
 public function _findPlugins()
 {
     $plugin_dirs = AkFileSystem::dir(AK_PLUGINS_DIR, array('dirs' => true, 'files' => false));
     $this->_available_plugins = array();
     foreach ($plugin_dirs as $plugin_dir) {
         $plugin_dir = array_pop($plugin_dir);
         if ($plugin_dir[0] != '.') {
             $this->_available_plugins[] = $plugin_dir;
         }
     }
 }