function saveReport() { if ($this->report == '') { $this->renderReport(); } Ak::file_put_contents('profiler_results.txt', $this->report); }
function up_1() { $new_code = ' private function __call ($method, $args) { if(substr($method,0,4) == \'find\'){ $finder = substr(AkInflector::underscore($method), 5); list($type, $columns) = explode(\'by_\', $finder); $callback = strstr($type,\'create\') ? \'findOrCreateBy\' : (strstr($type,\'first\') || !strstr($type,\'all\') ? \'findFirstBy\' : \'findAllBy\'); $columns = strstr($columns, \'_and_\') ? explode(\'_and_\', $columns) : array($columns); array_unshift($args, join(\' AND \', $columns)); return Ak::call_user_func_array(array(&$this,$callback), $args); } $backtrace = debug_backtrace(); trigger_error(\'Call to undefined method \'.__CLASS__.\'::\'.$method.\'() in <b>\'.$backtrace[1][\'file\'].\'</b> on line <b>\'.$backtrace[1][\'line\'].\'</b> reported \', E_USER_ERROR); } '; $original_class = Ak::file_get_contents(AK_APP_DIR.DS.'shared_model.php'); if(strstr($original_class, '__call')){ trigger_error('You seem to have a __call method on your shared model. This plugin can\'t be installed as it will conflict with your existing code.', E_USER_ERROR); } $modified_class = preg_replace('/ActiveRecord[ \n\t]*extends[ \n\t]*AkActiveRecord[ \n\t]*[ \n\t]*{/i', "ActiveRecord extends AkActiveRecord \n{\n\n$new_code", $original_class); Ak::file_put_contents(AK_APP_DIR.DS.'shared_model.php', $modified_class); }
function _createNewTestingModel($test_model_name) { static $shutdown_called; switch ($test_model_name) { case 'AkTestNestedCategory': $model_source = '<?php class AkTestNestedCategory extends AkActiveRecord { var $act_as = "nested_set"; } ?>'; break; default: $model_source = '<?php class ' . $test_model_name . ' extends AkActiveRecord { } ?>'; break; } $file_name = AkInflector::toModelFilename($test_model_name); if (!Ak::file_put_contents($file_name, $model_source)) { die('Ooops!, in order to perform this test, you must set your app/model permissions so this can script can create and delete files into/from it'); } if (!in_array($file_name, get_included_files()) && !class_exists($test_model_name)) { include $file_name; } else { return false; } $this->_testing_models_to_delete[] = $file_name; if (!isset($shutdown_called)) { $shutdown_called = true; register_shutdown_function(array(&$this, '_deleteTestingModels')); } return true; }
function createTemplate($file_name, $content = 'Dummy') { $file_name = str_replace('/', DS, $file_name); $file_name = AK_VIEWS_DIR . DS . $file_name; $this->assertTrue((bool) Ak::file_put_contents($file_name, $content)); $this->created_files[] = $file_name; }
function generate() { $this->_preloadPaths(); $this->class_name = AkInflector::camelize($this->class_name); $files = array( 'model'=>AkInflector::toModelFilename($this->class_name), 'unit_test'=>AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->underscored_model_name.'.php', 'model_fixture.tpl'=>AK_TEST_DIR.DS.'fixtures'.DS.$this->model_path, 'installer_fixture.tpl'=>AK_TEST_DIR.DS.'fixtures'.DS.$this->installer_path ); $this->_template_vars = (array)$this; foreach ($files as $template=>$file_path){ $this->save($file_path, $this->render($template)); } $installer_path = AK_APP_DIR.DS.'installers'.DS.$this->underscored_model_name.'_installer.php'; if(!file_exists($installer_path)){ $this->save($installer_path, $this->render('installer')); } $unit_test_runner = AK_TEST_DIR.DS.'unit.php'; if(!file_exists($unit_test_runner)){ Ak::file_put_contents($unit_test_runner, file_get_contents(AK_FRAMEWORK_DIR.DS.'test'.DS.'app.php')); } }
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); $this->assertFalse(file_exists(AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.'the_models.yaml')); Ak::file_put_contents(AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.'the_models.yaml',$yaml); $unit_tester->installAndIncludeModels(array('TheModel'=>'id,name')); $this->assertFalse($TheModel->find()); $this->assertEqual($TheModel->count(),0); $unit_tester->installAndIncludeModels(array('TheModel'=>'id,name'),array('populate'=>true)); $this->assertEqual($TheModel->count(),4); unlink(AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.'the_models.yaml'); }
public function Test_file_put_contents() { $file_name = AK_TMP_DIR.DS.'test_file_1.txt'; $content = 'This is the content of file 1'; $this->assertFalse(!Ak::file_put_contents($file_name, $content)); $file_name = '/cache'.DS.'test_file_1.txt'; $content = 'This is the NEW content for file 1'; $this->assertFalse(!Ak::file_put_contents($file_name, $content)); $file_name = AK_TMP_DIR.DS.'test_file_2.txt'; $content = "\n\rThis is the content of file 2\n"; $this->assertFalse(!Ak::file_put_contents($file_name, $content)); $file_name = 'cache'.DS.'test_file_3.txt'; $content = "\rThis is the content of file 3\r\n"; $this->assertFalse(!Ak::file_put_contents($file_name, $content)); $file_name = 'cache/test_file_4.txt'; $content = "\rThis is the content of file 4\r\n"; $this->assertFalse(!Ak::file_put_contents($file_name, $content)); $file_name = 'ak_test_folder/test_file.txt'; $content = "\rThis is the content of the test file"; $this->assertFalse(!Ak::file_put_contents($file_name, $content)); $file_name = 'ak_test_folder/new_folder/test_file.txt'; $content = "\rThis is the content of the test file"; $this->assertFalse(!Ak::file_put_contents($file_name, $content)); }
public function test_get_extra_resources() { $this->photo_path = AK_TEST_DIR . DS . 'fixtures' . DS . 'public' . DS . 'images' . DS . 'cristobal.jpg'; $this->watermark = AK_TEST_DIR . DS . 'fixtures' . DS . 'public' . DS . 'images' . DS . 'watermark.png'; if (!is_file($this->photo_path)) { Ak::file_put_contents($this->photo_path, Ak::url_get_contents('http://www.akelos.org/testing_resources/images/cristobal.jpg')); Ak::file_put_contents($this->watermark, Ak::url_get_contents('http://www.akelos.org/testing_resources/images/watermark.png')); } $this->_run_extra_tests = is_file($this->photo_path); }
function _createNewTestingModel($test_model_name) { static $shutdown_called; switch ($test_model_name) { case 'AkTestPerson': $model_source = '<?php class AkTestPerson extends AkActiveRecord { function validate() { $this->validatesPresenceOf("first_name"); } function validateOnCreate() { $this->validatesAcceptanceOf("tos"); } function validateOnUpdate() { $this->validatesPresenceOf("email"); } } ?>'; break; default: $model_source = '<?php class '.$test_model_name.' extends AkActiveRecord { } ?>'; break; } $file_name = AkInflector::toModelFilename($test_model_name); if(!Ak::file_put_contents($file_name,$model_source)){ die('Ooops!, in order to perform this test, you must set your app/model permissions so this can script can create and delete files into/from it'); } if(!in_array($file_name, get_included_files()) && !class_exists($test_model_name)){ include($file_name); }else { return false; } $this->_testing_models_to_delete[] = $file_name; if(!isset($shutdown_called)){ $shutdown_called = true; register_shutdown_function(array(&$this,'_deleteTestingModels')); } return true; }
function _getMenuOptionsForControllersInModule($type = 'admin') { $controllers = (Ak::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)){ Ak::file_put_contents(AK_CONFIG_DIR.DS.$options_file, Ak::convert('array', 'yaml', array('default'=>$menu_options))); } return $menu_options; }
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; Ak::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; }
function init() { $this->ext = empty($this->ext) ? 'doc' : strtolower(trim($this->ext, '.')); $this->tmp_name = Ak::randomString(); if (empty($this->source_file)) { $this->source_file = AK_CACHE_DIR . DS . $this->tmp_name . '.' . $this->ext; Ak::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 = 'txt'; $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_CACHE_DIR . DS . $this->destination_file_name : $this->destination_file; }
function init() { if (empty($this->handler)) { require_once AK_VENDOR_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_CACHE_DIR . DS . $this->tmp_name . '.xls'; Ak::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; } }
function uncompress($compressed_data, $format = 'gzip') { $key = Ak::randomString(15); $compressed_file = AK_TMP_DIR . DS . 's' . $key; $uncompressed_file = AK_TMP_DIR . DS . 'd' . $key; if (Ak::file_put_contents($compressed_file, $compressed_data, array('base_path' => AK_TMP_DIR))) { $compressed = gzopen($compressed_file, "r"); $uncompressed = fopen($uncompressed_file, "w"); while (!gzeof($compressed)) { $string = gzread($compressed, 4096); fwrite($uncompressed, $string, strlen($string)); } gzclose($compressed); fclose($uncompressed); } else { trigger_error(Ak::t('Could not write to temporary directory for generating uncompressing file using Ak::uncompress(). Please provide write access to %dirname', array('%dirname' => AK_TMP_DIR)), E_USER_ERROR); } $result = Ak::file_get_contents($uncompressed_file, array('base_path' => AK_TMP_DIR)); return $result; }
function relativizeStylesheetPaths() { $asset_path = $this->_getAssetBasePath(); if($this->hasUrlSuffix() || !empty($asset_path)){ $url_suffix = trim($this->getUrlSuffix(),'/'); if(!empty($asset_path)){ $url_suffix = trim($url_suffix.'/'.$asset_path,'/'); } foreach ($this->stylesheets as $stylesheet) { $filename = AK_PUBLIC_DIR.DS.'stylesheets'.DS.$stylesheet.'.css'; $relativized_css = preg_replace("/url\((\'|\")?\/images/","url($1/$url_suffix/images", @Ak::file_get_contents($filename)); empty($relativized_css) ? null : @Ak::file_put_contents($filename, $relativized_css); } } }
<?php error_reporting(E_ALL); defined('AK_ENVIRONMENT') ? null : define('AK_ENVIRONMENT', 'testing'); defined('AK_TEST_DIR') ? null : define('AK_TEST_DIR', str_replace(DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php', '', __FILE__)); defined('AK_APP_DIR') ? null : define('AK_APP_DIR', AK_TEST_DIR . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'app'); defined('AK_PUBLIC_DIR') ? null : define('AK_PUBLIC_DIR', AK_TEST_DIR . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'public'); defined('AK_TEST_HELPERS_DIR') ? null : define('AK_TEST_HELPERS_DIR', AK_TEST_DIR . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'helpers'); 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)); defined('AK_ENABLE_AKELOS_ARGS') ? null : define('AK_ENABLE_AKELOS_ARGS', true); //define('AK_SKIP_DB_CONNECTION',isset($db) && $db === false); defined('AK_URL_REWRITE_ENABLED') ? null : define('AK_URL_REWRITE_ENABLED', true); include_once substr(AK_TEST_DIR, 0, -5) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; defined('AK_APP_LOCALES') ? null : define('AK_APP_LOCALES', 'en,es'); defined('AK_PUBLIC_LOCALES') ? null : define('AK_PUBLIC_LOCALES', AK_APP_LOCALES); defined('AK_ACTIVE_RECORD_INTERNATIONALIZE_MODELS_BY_DEFAULT') ? null : define('AK_ACTIVE_RECORD_INTERNATIONALIZE_MODELS_BY_DEFAULT', true); defined('AK_ACTIVE_RECORD_ENABLE_AUTOMATIC_SETTERS_AND_GETTERS') ? null : define('AK_ACTIVE_RECORD_ENABLE_AUTOMATIC_SETTERS_AND_GETTERS', true); defined('AK_TESTING_URL') ? null : define('AK_TESTING_URL', rtrim(AK_URL, '/') . '/test/fixtures/public'); defined('AK_TESTING_REWRITE_BASE') ? null : define('AK_TESTING_REWRITE_BASE', false); defined('AK_LIB_TESTS_DIRECTORY') ? null : define('AK_LIB_TESTS_DIRECTORY', AK_TEST_DIR . DS . 'unit' . DS . 'lib'); if (AK_TESTING_REWRITE_BASE) { Ak::file_put_contents(AK_BASE_DIR . '/test/fixtures/public/.htaccess', str_replace('# RewriteBase /test/fixtures/public', 'RewriteBase ' . AK_TESTING_REWRITE_BASE, Ak::file_get_contents(AK_BASE_DIR . '/test/fixtures/public/.htaccess'))); } if (defined('AK_TEST_DATABASE_ON')) { $default_profile = array_key_exists($argv[count($argv) - 1], $database_settings) ? array_pop($argv) : AK_ENVIRONMENT; define('AK_DEFAULT_DATABASE_PROFILE', $default_profile); include_once AK_LIB_DIR . DS . 'Ak.php'; Ak::db(); unset($default_profile); } require_once AK_LIB_DIR . DS . 'AkUnitTest.php';
function _get_file_details($key) { $key = preg_replace('/[^A-Z^a-z^0-9]/', '', $key); $file = $this->get_persisted_file($key); if (!empty($file)) { Ak::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; } }
public function writeCache($config, $namespace, $environment = TPV_MODE, $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 (!Ak::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)) . ' ' . Ak::getFileAndNumberTextForError(1), E_USER_ERROR); return false; } else { return true; } }
public function _createJoinClass() { $options = $this->getOptions($this->association_id); $class_file_code = "<?php \n\n//This code was generated automatically by the active record hasAndBelongsToMany Method\n\n"; $class_code = "class {$options['join_class_name']} extends {$options['join_class_extends']} {\n public \$_avoidTableNameValidation = true;\n public function {$options['join_class_name']}()\n {\n \$this->setModelName(\"{$options['join_class_name']}\");\n \$attributes = (array)func_get_args();\n \$this->setTableName('{$options['join_table']}', true, true);\n \$this->init(\$attributes);\n }\n}"; $class_file_code .= $class_code . "\n\n?>"; $join_file = AkInflector::toModelFilename($options['join_class_name']); if ($this->_automatically_create_join_model_files && !file_exists($join_file) && @Ak::file_put_contents($join_file, $class_file_code)) { require_once $join_file; } else { eval($class_code); } return class_exists($options['join_class_name']); }
function _saveCompiledTemplate() { $options = array('base_path' => (AK_COMPILED_VIEWS_DIR ? AK_TMP_DIR : AK_BASE_DIR)); if(defined('AK_UPLOAD_FILES_USING_FTP') && AK_UPLOAD_FILES_USING_FTP && !strstr($options['base_path'], AK_BASE_DIR)){ $options['ftp'] = false; } Ak::file_put_contents($this->_getCompiledTemplatePath(), $this->_options['code'], $options); }
function _checkInstallDependencies() { if (isset($this->php_min_version)) { if (version_compare(PHP_VERSION, $this->php_min_version, '<')) { echo "\n"; Ak::t("This plugin requires at least php version: %version", array('%version', $this->php_min_version)); echo "\n"; return false; } } if (isset($this->php_max_version)) { if (version_compare(PHP_VERSION, $this->php_max_version, '>')) { echo "\n"; Ak::t("This plugin runs only on php version <= %version", array('%version', $this->php_min_version)); echo "\n"; return false; } } if (isset($this->dependencies)) { $this->dependencies = Ak::toArray($this->dependencies); $pluginManager = new AkPluginManager(); $plugins = $pluginManager->getInstalledPlugins(); $missing = array(); foreach ($this->dependencies as $dependency) { if (!in_array($dependency, $plugins)) { $missing[] = $dependency; } } if (!empty($missing)) { echo "\n"; $params = array('plugin' => AkT('plugin', 'quantify(' . count($missing) . ')'), 'missing' => AkT($missing, 'toSentence')); echo Ak::t("This plugin depends on the %plugin %missing. Please install the missing plugins first.", $params); echo "\n"; return false; } else { /** * register the dependent plugins */ foreach ($this->dependencies as $dependency) { $dependencyFile = AK_PLUGINS_DIR . DS . $dependency . DS . 'dependent_plugins'; if ($fileExists = file_exists($dependencyFile)) { $dependendPlugins = file($dependencyFile); } else { $dependendPlugins = array(); } if (!in_array($this->plugin_name, $dependendPlugins)) { $dependendPlugins[] = $this->plugin_name; } if (!empty($dependendPlugins)) { Ak::file_put_contents($dependencyFile, implode("\n", $dependendPlugins)); } else { if ($fileExists) { unlink($dependencyFile); } } } } } return true; }
function _getImagePath($path) { 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 = AK_TMP_DIR.DS.'mailer'.DS.'remote_images'.DS.md5($base_file_name['dirname']).DS.$base_file_name.'.'.$path_info['extension']; if(!file_exists($local_path) || (time() > @filemtime($local_path)+7200)){ if(!Ak::file_put_contents($local_path, Ak::url_get_contents($path))){ return ''; } } return $local_path; } } $path = AK_PUBLIC_DIR.Ak::sanitize_include($path); if(!file_exists($path)){ $path = ''; } return $path; }
/** * @todo Refactor this method */ function updateLocaleFiles() { $new_core_entries = array(); $new_controller_entries = array(); $new_controller_files = array(); $used_entries = AkLocaleManager::getUsedLanguageEntries(); require AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php'; $core_dictionary = $dictionary; $controllers_dictionaries = array(); foreach ($used_entries as $k => $v) { // This is a controller file if (is_array($v)) { if (!isset($controllers_dictionaries[$k])) { $controller = $k; $module_lang_file = AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php'; if (is_file($module_lang_file)) { require $module_lang_file; $controllers_dictionaries[$controller] = array_merge((array) $dictionary, (array) $v); $existing_controllers_dictionaries[$controller] = (array) $dictionary; } else { $controllers_dictionaries[$controller] = (array) $v; $new_controller_files[$controller] = $module_lang_file; } } } else { if (!isset($core_dictionary[$k])) { $new_core_entries[$k] = $k; } } } $dictionary_file = ''; foreach ($new_controller_files as $controller => $file_name) { $dictionary_file = "<?php\n\n// File created on: " . date("Y-m-d G:i:s", Ak::time()) . "\n\n\$dictionary = array();\n\n"; foreach ($controllers_dictionaries[$controller] as $k => $entry) { $entry = str_replace("'", "\\'", $entry); $dictionary_file .= "\n\$dictionary['{$entry}'] = '{$entry}';"; } unset($controllers_dictionaries[$controller]); $dictionary_file .= "\n\n\n?>"; Ak::file_put_contents($file_name, $dictionary_file); } // Module files foreach ((array) $controllers_dictionaries as $controller => $controller_entries) { $dictionary_file = ''; foreach ($controller_entries as $entry) { if ($entry == '' || isset($existing_controllers_dictionaries[$controller][$entry])) { continue; } $entry = str_replace("'", "\\'", $entry); $dictionary_file .= "\n\$dictionary['{$entry}'] = '{$entry}';"; } if ($dictionary_file != '') { $original_file = Ak::file_get_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php'); $original_file = rtrim($original_file, "?> \n\r"); $new_entries = "\n\n// " . date("Y-m-d G:i:s", Ak::time()) . "\n\n" . $dictionary_file . "\n\n\n?>\n"; $dictionary_file = $original_file . $new_entries; Ak::file_put_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php', $dictionary_file); foreach (Ak::langs() as $lang) { if ($lang != AK_FRAMEWORK_LANGUAGE) { $lang_file = @Ak::file_get_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php'); if (empty($lang_file)) { $dictionary_file = $original_file; } else { $lang_file = rtrim($lang_file, "?> \n\r"); $dictionary_file = $lang_file; } Ak::file_put_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php', $dictionary_file . $new_entries); } } } } // Core locale files $dictionary_file = ''; foreach ($new_core_entries as $core_entry) { if ($core_entry == '') { continue; } $core_entry = str_replace("'", "\\'", $core_entry); $dictionary_file .= "\n\$dictionary['{$core_entry}'] = '{$core_entry}';"; } if ($dictionary_file != '') { $original_file = Ak::file_get_contents(AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php'); $original_file = rtrim($original_file, "?> \n\r"); $new_entries = "\n\n// " . date("Y-m-d G:i:s", Ak::time()) . "\n\n" . $dictionary_file . "\n\n\n?>\n"; $dictionary_file = $original_file . $new_entries; Ak::file_put_contents(AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php', $dictionary_file); foreach (Ak::langs() as $lang) { if ($lang != AK_FRAMEWORK_LANGUAGE) { $lang_file = Ak::file_get_contents(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php'); if (empty($lang_file)) { $dictionary_file = str_replace("\$locale['description'] = 'English';", "\$locale['description'] = '{$lang}';", $original_file); } else { $lang_file = rtrim($lang_file, "?> \n\r"); $dictionary_file = $lang_file; } Ak::file_put_contents(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php', $dictionary_file . $new_entries); } } } }
function testFtpSettings() { if (!$this->canUseFtpFileHandling()) { return false; } $ftp_path = 'ftp://' . $this->getFtpUser() . ':' . $this->getFtpPassword() . '@' . $this->getFtpHost() . $this->getFtpPath(); @define('AK_UPLOAD_FILES_USING_FTP', true); @define('AK_READ_FILES_USING_FTP', false); @define('AK_DELETE_FILES_USING_FTP', true); @define('AK_FTP_PATH', $ftp_path); @define('AK_FTP_AUTO_DISCONNECT', true); if (@Ak::file_put_contents(AK_CONFIG_DIR . DS . 'test_file.txt', 'hello from ftp')) { $text = @Ak::file_get_contents(AK_CONFIG_DIR . DS . 'test_file.txt'); @Ak::file_delete(AK_CONFIG_DIR . DS . 'test_file.txt'); } $this->ftp_enabled = isset($text) && $text == 'hello from ftp'; return $this->ftp_enabled; }
public 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); } Ak::file_put_contents($file_name, serialize($config)); } else { if (AK_LOG_EVENTS) { $Logger->message('Skipping writing of cache file: ' . $file_name); } } } }
function Test_of_compress_decompress() { $original = Ak::file_get_contents(__FILE__); $compressed = Ak::compress($original); Ak::file_put_contents(AK_TMP_DIR . DS . 'gzip_test.gz', $compressed, array('base_path' => AK_TMP_DIR)); $this->assertTrue(strlen($compressed) < strlen($original)); $compressed_file = Ak::file_get_contents(AK_TMP_DIR . DS . 'gzip_test.gz', array('base_path' => AK_TMP_DIR)); $this->assertEqual($compressed_file, $compressed); $uncompressed_from_file = Ak::uncompress($compressed_file); $uncompressed_from_string = Ak::uncompress($compressed); $this->assertEqual($uncompressed_from_file, $uncompressed_from_string); }
public function Test_is_dir() { $path = 'invalid path'; $this->assertFalse(AkFtp::is_dir($path)); $path = 'this_is_a_file.txt'; Ak::file_put_contents('this_is_a_file.txt', ''); $this->assertFalse(AkFtp::is_dir($path)); AkFtp::make_dir('tmp_test_dir'); Ak::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'); }
function setInstalledVersion($version, $options = array()) { return Ak::file_put_contents($this->_versionPath($options), $version); }
public function persistCookies() { if($this->_cookie_path){ $cookies_from_response = $this->HttpRequest->getResponseCookies(); if(!empty($this->_persisted_cookie)){ $this->HttpRequest->_cookies = array(); $persisted_cookies = $this->HttpRequest->_response->_parseCookie($this->_persisted_cookie); $this->HttpRequest->_cookies = $cookies_from_response; } if(!empty($cookies_from_response)){ $all_cookies = array_merge(isset($persisted_cookies)?$persisted_cookies:array(), $cookies_from_response); $cookies = array(); foreach($all_cookies as $cookie){ if(!empty($cookie['value'])){ $cookies[$cookie['name']] = "{$cookie['name']}={$cookie['value']}"; } } $cookie_string = trim(join($cookies, '; ')); Ak::file_put_contents($this->_cookie_path, $cookie_string); } } }
function generate() { //Generate models if they don't exist $model_files = array( 'model'=>$this->model_file_path, 'installer'=>AK_APP_DIR.DS.'installers'.DS.$this->singular_name.'_installer.php', 'model_unit_test'=>AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->singular_name.'.php', 'model_fixture'=> AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'models'.DS.$this->singular_name.'.php', 'installer_fixture'=>AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'installers'.DS.$this->singular_name.'_installer.php' ); $this->_template_vars = (array)$this; foreach ($model_files as $template=>$file_path){ if(!file_exists($file_path)){ $this->save($file_path, $this->render($template, !empty($this->sintags))); } } // We check for common testing files $common_testing_files = array( 'fixtures'.DS.'config'.DS.'config.php', 'fixtures'.DS.'app'.DS.'shared_model.php' ); foreach ($common_testing_files as $common_testing_file){ if(!file_exists(AK_TEST_DIR.DS.$common_testing_file)){ $this->save(AK_TEST_DIR.DS.$common_testing_file, file_get_contents(AK_FRAMEWORK_DIR.DS.'test'.DS.$common_testing_file)); } } if(file_exists($this->model_file_path)){ require_once(AK_APP_DIR.DS.'shared_model.php'); require_once($this->model_file_path); if(class_exists($this->model_name)){ $ModelInstance =& new $this->model_name; $table_name = $ModelInstance->getTableName(); if(!empty($table_name)){ $this->content_columns = $ModelInstance->getContentColumns(); unset( $this->content_columns['updated_at'], $this->content_columns['updated_on'], $this->content_columns['created_at'], $this->content_columns['created_on'] ); } $internationalized_columns = $ModelInstance->getInternationalizedColumns(); foreach ($internationalized_columns as $column_name=>$languages){ foreach ($languages as $lang){ $this->content_columns[$column_name] = $this->content_columns[$lang.'_'.$column_name]; $this->content_columns[$column_name]['name'] = $column_name; unset($this->content_columns[$lang.'_'.$column_name]); } } } } $this->_template_vars = (array)$this; foreach ($this->files as $template=>$file_path){ $this->save($file_path, $this->render($template, !empty($this->sintags))); } foreach ($this->user_actions as $action=>$file_path){ $this->assignVarToTemplate('action',$action); $this->save($file_path, $this->render('view', !empty($this->sintags))); } $unit_test_runner = AK_TEST_DIR.DS.'unit.php'; if(!file_exists($unit_test_runner)){ Ak::file_put_contents($unit_test_runner, file_get_contents(AK_FRAMEWORK_DIR.DS.'test'.DS.'app.php')); } }