function makeClassExtensible($class_name_to_extend) { list($checksum, $source) = $this->_getExtensionSourceAndChecksum($class_name_to_extend); $merge_path = AK_TMP_DIR . DS . '.lib'; if ($source) { if (preg_match_all('/[ \\n\\t]*([a-z]+)[ \\n\\t]*extends[ \\n\\t]*(' . $class_name_to_extend . ')[ \\n\\t]*[ \\n\\t]*{/i', $source, $matches)) { $replacements = array(); $extended_by = array(); foreach ($matches[2] as $k => $class_to_extend) { if (empty($last_method) && class_exists($class_to_extend)) { $last_method = $class_to_extend; } if ($class_to_extend == $last_method || !empty($extended_by[$class_to_extend]) && in_array($last_method, $extended_by[$class_to_extend])) { if (!class_exists($matches[1][$k])) { $replacements[trim($matches[0][$k], "\n\t {")] = $matches[1][$k] . ' extends ' . $last_method; $last_method = $matches[1][$k]; $extended_by[$class_to_extend][] = $last_method; } else { trigger_error(Ak::t('The class %class is already defined and can\'t be used for extending %parent_class', array('%class' => $matches[1][$k], '%parent_class' => $class_name_to_extend)), E_NOTICE); } } } $source = str_replace(array_keys($replacements), array_values($replacements), $source); } $source = "{$source}<?php class Extensible{$class_name_to_extend} extends {$last_method}{} ?>"; if (md5($source) != @md5_file($merge_path . DS . 'Extensible' . $class_name_to_extend . '.php')) { Ak::file_put_contents($merge_path . DS . 'Extensible' . $class_name_to_extend . '.php', $source); Ak::file_put_contents($merge_path . DS . 'checksums' . DS . 'Extensible' . $class_name_to_extend, $checksum); } } include_once $merge_path . DS . 'Extensible' . $class_name_to_extend . '.php'; }
function checkForCollisions(&$directory_structure, $base_path = AK_ADMIN_PLUGIN_FILES_DIR) { foreach ($directory_structure as $k=>$node){ if(!empty($this->skip_all)){ return ; } $path = str_replace(AK_ADMIN_PLUGIN_FILES_DIR, AK_BASE_DIR, $base_path.DS.$node); if(is_file($path)){ $message = Ak::t('File %file exists.', array('%file'=>$path)); $user_response = AkInstaller::promptUserVar($message."\n d (overwrite mine), i (keep mine), a (abort), O (overwrite all), K (keep all)", 'i'); if($user_response == 'i'){ unset($directory_structure[$k]); } elseif($user_response == 'O'){ return false; } elseif($user_response == 'K'){ $directory_structure = array(); return false; }elseif($user_response != 'd'){ echo "\nAborting\n"; exit; } }elseif(is_array($node)){ foreach ($node as $dir=>$items){ $path = $base_path.DS.$dir; if(is_dir($path)){ if($this->checkForCollisions($directory_structure[$k][$dir], $path) === false){ $this->skip_all = true; return; } } } } } }
function hasCollisions() { $this->collisions = array(); $this->_preloadPaths(); $this->actions = empty($this->actions) ? array() : (array)$this->actions; $files = array( AK_APP_DIR.DS.$this->controller_path, AK_TEST_DIR.DS.'functional'.DS.'app'.DS.$this->controller_path, AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.$this->controller_path, AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'helpers'.DS.$this->underscored_controller_name."_helper.php", AK_HELPERS_DIR.DS.$this->underscored_controller_name."_helper.php" ); foreach ($this->actions as $action){ $files[] = AK_VIEWS_DIR.DS.$this->module_path.AkInflector::underscore($this->controller_name).DS.$action.'.tpl'; } foreach ($files as $file_name){ if(file_exists($file_name)){ $this->collisions[] = Ak::t('%file_name file already exists',array('%file_name'=>$file_name)); } } return count($this->collisions) > 0; }
function generateModel($model_name) { $model_source_code = "class " . $model_name . " extends ActiveRecord {} "; $has_errors = @eval($model_source_code) === false; if ($has_errors) { trigger_error(Ak::t('Could not declare the model %modelname.', array('%modelname' => $model_name)), E_USER_ERROR); } }
function Test_t() { $text_to_translate = 'Hello, %name, today is %weekday'; $vars_to_replace = array('%name' => 'Bermi', '%weekday' => 'monday'); $this->assertEqual(Ak::t($text_to_translate), 'Hello, %name, today is %weekday', 'String with tokens but no replacement array given.'); $this->assertEqual(Ak::t($text_to_translate), 'Hello, %name, today is %weekday', 'String with tokens but no replacement array given.'); $this->assertEqual(Ak::t($text_to_translate, $vars_to_replace), 'Hello, Bermi, today is monday'); }
public function &load($email_file) { if (!file_exists($email_file)) { trigger_error(Ak::t('Cannot find mail file at %path', array('%path' => $email_file)), E_USER_ERROR); } $Mail = new AkMail((array) AkMailParser::parse(file_get_contents($email_file))); return $Mail; }
public function hasCollisions() { $this->collisions = array(); $this->destination_path = rtrim($this->destination_path, DS); if (is_dir($this->destination_path)) { $this->collisions[] = Ak::t('%path already exists', array('%path' => $this->destination_path)); } return count($this->collisions) > 0; }
/** * To prevent users from using something insecure like "Password" we make sure that the * secret they've provided is at least 30 characters in length. */ private function ensureSecretSecure() { if (empty($this->options['secret'])) { throw new ArgumentException(Ak::t('A secret is required to generate an integrity hash for cookie session data. Use ' . 'AkConfig::setOption(\'action_controller.session\', ' . 'array("key" => "_myapp_session", "secret" => "some secret ' . 'phrase of at least %length characters")); in config/environment.php', array('%length' => self::SECRET_MIN_LENGTH))); } if (strlen($this->options['secret']) < self::SECRET_MIN_LENGTH) { throw new ArgumentException(Ak::t('Secret should be something secure, ' . 'like "%rand". The value you provided "%secret", ' . 'is shorter than the minimum length of %length characters', array('%length' => self::SECRET_MIN_LENGTH, '%rand' => Ak::uuid(), '%secret' => $this->options['secret']))); } }
function &recognize($Map = null) { AK_ENVIRONMENT != 'setup' ? $this->_connectToDatabase() : null; $this->_startSession(); $this->_enableInternationalizationSupport(); $this->_mapRoutes($Map); $params = $this->getParams(); $module_path = $module_class_peffix = ''; if (!empty($params['module'])) { $module_path = trim(str_replace(array('/', '\\'), DS, Ak::sanitize_include($params['module'], 'high')), DS) . DS; $module_shared_model = AK_CONTROLLERS_DIR . DS . trim($module_path, DS) . '_controller.php'; $module_class_peffix = str_replace(' ', '_', AkInflector::titleize(str_replace(DS, ' ', trim($module_path, DS)))) . '_'; } $controller_file_name = AkInflector::underscore($params['controller']) . '_controller.php'; $controller_class_name = $module_class_peffix . AkInflector::camelize($params['controller']) . 'Controller'; $controller_path = AK_CONTROLLERS_DIR . DS . $module_path . $controller_file_name; include_once AK_APP_DIR . DS . 'application_controller.php'; if (!empty($module_path) && file_exists($module_shared_model)) { include_once $module_shared_model; } if (!is_file($controller_path) || !(include_once $controller_path)) { defined('AK_LOG_EVENTS') && AK_LOG_EVENTS && $this->Logger->error('Controller ' . $controller_path . ' not found.'); if (AK_ENVIRONMENT == 'development') { trigger_error(Ak::t('Could not find the file /app/controllers/<i>%controller_file_name</i> for ' . 'the controller %controller_class_name', array('%controller_file_name' => $controller_file_name, '%controller_class_name' => $controller_class_name)), E_USER_ERROR); } elseif (@(include AK_PUBLIC_DIR . DS . '404.php')) { $response = new AkTestResponse(); $response->addHeader('Status', 404); return false; //exit; } else { //header("HTTP/1.1 404 Not Found"); $response = new AkResponse(); $response->addHeader('Status', 404); return false; //die('404 Not found'); } } if (!class_exists($controller_class_name)) { defined('AK_LOG_EVENTS') && AK_LOG_EVENTS && $this->Logger->error('Controller ' . $controller_path . ' does not implement ' . $controller_class_name . ' class.'); if (AK_ENVIRONMENT == 'development') { trigger_error(Ak::t('Controller <i>%controller_name</i> does not exist', array('%controller_name' => $controller_class_name)), E_USER_ERROR); } elseif (@(include AK_PUBLIC_DIR . DS . '405.php')) { exit; } else { $response = new AkResponse(); $response->addHeader('Status', 405); return false; //header("HTTP/1.1 405 Method Not Allowed"); //die('405 Method Not Allowed'); } } $Controller =& new $controller_class_name(array('controller' => true)); $Controller->_module_path = $module_path; isset($_SESSION) ? $Controller->session =& $_SESSION : null; return $Controller; }
public function setDate($date = null, $validate = true) { $date = trim($date); $is_valid = preg_match("/^" . AK_ACTION_MAILER_RFC_2822_DATE_REGULAR_EXPRESSION . "\$/", $date); $date = !$is_valid ? date('r', empty($date) ? Ak::time() : (!is_numeric($date) ? strtotime($date) : $date)) : $date; if ($validate && !$is_valid && !preg_match("/^" . AK_ACTION_MAILER_RFC_2822_DATE_REGULAR_EXPRESSION . "\$/", $date)) { trigger_error(Ak::t('You need to supply a valid RFC 2822 date. You can just leave the date field blank or pass a timestamp and Akelos will automatically format the date for you'), E_USER_ERROR); } $this->date = $date; }
function setAssociationId($association_id) { $association_id = strtolower(AkInflector::underscore($association_id)); if (isset($this->Owner->{$association_id})) { trigger_error(Ak::t('Could not load %association_id on %model_name because "%model_name->%association_id" attribute ' . 'is already defided and can\' be used as an association placeholder', array('%model_name' => $this->Owner->getModelName(), '%association_id' => $association_id)), E_USER_ERROR); return false; } else { return $association_id; } }
function hasCollisions() { $this->collisions = array(); foreach (array_merge(array_values($this->files), array_values($this->user_actions)) as $file_name) { if (file_exists($file_name)) { $this->collisions[] = Ak::t('%file_name file already exists', array('%file_name' => $file_name)); } } return count($this->collisions) > 0; }
public function convert() { if (!xml_parse($this->_parser, $this->source)) { $this->addError(Ak::t('DBDesigner file is not well-formed.') . ' ' . xml_error_string(xml_get_error_code($this->_parser))); } foreach ($this->db_schema as $table => $create_text) { $this->db_schema[$table] = rtrim($create_text, ", \n"); } return $this->db_schema; }
public function __construct($client_driver) { $client_driver = AkInflector::underscore($client_driver); if (in_array($client_driver, $this->_available_drivers)) { $client_class_name = 'Ak' . AkInflector::camelize($client_driver) . 'Client'; require_once AK_ACTION_PACK_DIR . DS . 'action_web_service' . DS . 'clients' . DS . $client_driver . '.php'; $this->_Client = new $client_class_name($this); } else { trigger_error(Ak::t('Invalid Web Service driver provided. Available Drivers are: %drivers', array('%drivers' => join(', ', $this->_available_drivers))), E_USER_WARNING); } }
function set_db_user_and_pass(&$FrameworkSetup, &$db_user, &$db_pass, &$db_type, $defaults = true) { global $options; $db_type = prompt_var('Database type', 'mysql', $defaults ? @$options['database'] : null); $db_user = prompt_var('Database user', $FrameworkSetup->suggestUserName(), $defaults ? @$options['user'] : null); $db_pass = prompt_var('Database password', '', $defaults ? @$options['password'] : null); if (!@NewADOConnection("{$db_type}://{$db_user}:{$db_pass}@localhost")) { echo Ak::t('Could not connect to the database' . "\n"); set_db_user_and_pass($FrameworkSetup, $db_user, $db_pass, $db_type, false); } }
public function hasCollisions() { $this->collisions = array(); $this->namespace = AkInflector::underscore(Ak::first(explode(':', $this->task_name . ':'))); $this->task_name = AkInflector::underscore(Ak::last(explode(':', ':' . $this->task_name))); $this->destination_path = AK_TASKS_DIR . DS . $this->namespace; if (file_exists($this->destination_path . DS . $this->task_name . '.task.php')) { $this->collisions[] = Ak::t('%path already exists', array('%path' => $this->destination_path . DS . $this->task_name . '.task.php')); } return count($this->collisions) > 0; }
public function hasCollisions() { $this->collisions = array(); $this->generator_name = AkInflector::underscore($this->generator_name); $this->class_name = AK_APP_LIB_DIR . DS . 'generators' . DS . $this->generator_name; $this->destination_path = AK_APP_LIB_DIR . DS . 'generators' . DS . $this->generator_name; if (is_dir($this->destination_path)) { $this->collisions[] = Ak::t('%path already exists', array('%path' => $this->destination_path)); } return count($this->collisions) > 0; }
function _ensureIsActiveRecordInstance(&$ActiveRecordInstance) { if (is_object($ActiveRecordInstance) && method_exists($ActiveRecordInstance, 'actsLike')) { $this->_ActiveRecordInstance =& $ActiveRecordInstance; $this->observe(&$ActiveRecordInstance); } else { trigger_error(Ak::t('You are trying to set an object that is not an active record.'), E_USER_ERROR); return false; } return true; }
function hasCollisions() { $this->_setupCloner(); $this->collisions = array(); foreach ($this->files_to_clone as $origin => $destination) { if (file_exists($destination)) { $this->collisions[] = Ak::t('%file_name file already exists', array('%file_name' => $destination)); } } return count($this->collisions) > 0; }
function renameColumn($table_name,$column_name,$new_name) { $column_details = $this->selectOne("SHOW COLUMNS FROM $table_name LIKE '$column_name'"); if (!$column_details) { trigger_error(Ak::t("No such column '%column' in %table_name",array('%column'=>$column_name,'%table_name'=>$table_name)), E_USER_ERROR); return false; } $column_type_definition = $column_details['Type']; if ($column_details['Null']!=='YES') $column_type_definition .= ' not null'; if (!empty($column_details['Default'])) $column_type_definition .= " default '".$column_details['Default']."'"; return $this->execute("ALTER TABLE $table_name CHANGE COLUMN $column_name $new_name $column_type_definition"); }
public function setOptions($options = array()) { require_once AK_CONTRIB_DIR . DS . 'pear' . DS . 'Image' . DS . 'Tools.php'; $this->Image->Transform =& Image_Tools::factory('Watermark'); $default_options = array('image' => $this->Image->Transform->createImage($this->Image->image_path)); $this->options = array_merge($default_options, $options); if (empty($this->options['mark']) || !is_file($this->options['mark'])) { trigger_error(Ak::t('Option "mark" does not contain a valid Watermark image path'), E_USER_ERROR); } $this->_variablizeOptions_($this->options); $this->Image->Transform->set($this->options); }
function hasCollisions() { $this->_preloadPaths(); $this->collisions = array(); $files = array($this->service_path); foreach ($files as $file_name) { if (file_exists($file_name)) { $this->collisions[] = Ak::t('%file_name file already exists', array('%file_name' => $file_name)); } } return count($this->collisions) > 0; }
function sendHeaders($terminate_if_redirected = true) { /** * Fix a problem with IE 6.0 on opening downloaded files: * If Cache-Control: IE removes the file it just downloaded from * its cache immediately * after it displays the "open/save" dialog, which means that if you * hit "open" the file isn't there anymore when the application that * is called for handling the download is run, so let's workaround that */ if(isset($this->_headers['Cache-Control']) && $this->_headers['Cache-Control'] == 'no-cache'){ $this->_headers['Cache-Control'] = 'private'; } if(!empty($this->_headers['Status'])){ $status = $this->_getStatusHeader($this->_headers['Status']); array_unshift($this->_headers, $status ? $status : (strstr('HTTP/1.1 '.$this->_headers['Status'],'HTTP') ? $this->_headers['Status'] : 'HTTP/1.1 '.$this->_headers['Status'])); //unset($this->_headers['Status']); } else { $this->_headers['Status'] = $this->_default_status; } if(!empty($this->_headers) && is_array($this->_headers)){ $this->addHeader('Connection: close'); foreach ($this->_headers as $k=>$v){ if ($k == 'Status') continue; $header = trim((!is_numeric($k) ? $k.': ' : '').$v); $this->_headers_sent[] = $header; if(strtolower(substr($header,0,9)) == 'location:'){ $_redirected = true; if(AK_DESKTOP){ $javascript_redirection = '<title>'.Ak::t('Loading...').'</title><script type="text/javascript">location = "'.substr($header,9).'";</script>'; continue; } } if(strtolower(substr($header,0,13)) == 'content-type:'){ $_has_content_type = true; } AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Sending header: $header") : null; //header($header); } } if(empty($_has_content_type) && defined('AK_CHARSET') && (empty($_redirected) || (!empty($_redirected) && !empty($javascript_redirection)))){ //header('Content-Type: text/html; charset='.AK_CHARSET); $this->_headers_sent[] = 'Content-Type: text/html; charset='.AK_CHARSET; } if(!empty($javascript_redirection)){ echo $javascript_redirection; } $terminate_if_redirected ? (!empty($_redirected) ? $this->isRedirected(true) : null) : null; }
function redirect($url) { if (!headers_sent($file_name, $line_number)) { header("Location: {$url}"); exit; } else { trigger_error(Ak::t('Headers already sent in %file_name on line %line_number', array('%file_name' => $file_name, '%line_number' => $line_number)), E_NOTICE); echo "<meta http-equiv=\"refresh\" content=\"0;url={$url}\">"; echo Ak::t('Cannot redirect, for now please click this <a href="%url">link</a> instead', array('%url' => $url)); exit; } }
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; }
function hasCollisions() { $this->_preloadPaths(); $this->collisions = array(); $files = array(AkInflector::toModelFilename($this->class_name), AK_TEST_DIR . DS . 'unit' . DS . 'app' . DS . 'models' . DS . $this->underscored_model_name . '.php', AK_TEST_DIR . DS . 'fixtures' . DS . $this->model_path, AK_TEST_DIR . DS . 'fixtures' . DS . $this->installer_path); foreach ($files as $file_name) { if (file_exists($file_name)) { $this->collisions[] = Ak::t('%file_name file already exists', array('%file_name' => $file_name)); } } return count($this->collisions) > 0; }
/** * Defines the column name for use with single table inheritance. Can be overridden in subclasses. */ public function setInheritanceColumn($column_name) { if (!$this->_ActiveRecord->hasColumn($column_name)) { trigger_error(Ak::t('Could not set "%column_name" as the inheritance column as this column is not available on the database.', array('%column_name' => $column_name)) . ' ' . AkDebug::getFileAndNumberTextForError(1), E_USER_NOTICE); return false; } elseif ($this->_ActiveRecord->getColumnType($column_name) != 'string') { trigger_error(Ak::t('Could not set %column_name as the inheritance column as this column type is "%column_type" instead of "string".', array('%column_name' => $column_name, '%column_type' => $this->_ActiveRecord->getColumnType($column_name))) . ' ' . AkDebug::getFileAndNumberTextForError(1), E_USER_NOTICE); return false; } else { $this->_ActiveRecord->_inheritanceColumn = $column_name; return true; } }
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; }
function hasCollisions() { $this->_preloadPaths(); $this->collisions = array(); $files = array(AkInflector::toModelFilename($this->class_name), AK_TEST_DIR . DS . 'unit' . DS . 'app' . DS . 'models' . DS . $this->underscored_class_name . '.php'); foreach ($this->actions as $action) { $files[] = AK_VIEWS_DIR . DS . AkInflector::underscore($this->class_name) . DS . $action . '.tpl'; } foreach ($files as $file_name) { if (file_exists($file_name)) { $this->collisions[] = Ak::t('%file_name file already exists', array('%file_name' => $file_name)); } } return count($this->collisions) > 0; }
function _getDocumentationForMethod($ApiMethod) { $doc = !empty($ApiMethod->documentation) ? $ApiMethod->documentation . "\n" : ''; foreach (array('expects', 'returns') as $expects_or_returns) { if (!empty($ApiMethod->{$expects_or_returns})) { foreach ($ApiMethod->{$expects_or_returns} as $k => $type) { $doc .= "\n" . ($expects_or_returns == 'expects' ? Ak::t(AkInflector::ordinalize($k + 1)) . ' parameter as' : 'Returns') . " {$type}:"; if (!empty($ApiMethod->{$expects_or_returns . '_documentation'}[$k])) { $doc .= ' ' . $ApiMethod->{$expects_or_returns . '_documentation'}[$k]; } } } } return $doc; }