Fixed coding style, comments, and some trivial issues.
parent
b31c2510e2
commit
e312880573
|
@ -3134,14 +3134,13 @@ function drupal_group_css($css) {
|
|||
* @see system_element_info()
|
||||
*/
|
||||
function drupal_aggregate_css(&$css_groups) {
|
||||
// Only aggregate when the site is configured to do so, and not during an
|
||||
// update.
|
||||
if (defined('MAINTENANCE_MODE') && (MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update')) {
|
||||
$preprocess_css = FALSE;
|
||||
// Only aggregate during normal site operation.
|
||||
if (defined('MAINTENANCE_MODE')) {
|
||||
$preprocess_css = FALSE;
|
||||
}
|
||||
else {
|
||||
$config = config('system.performance');
|
||||
$preprocess_css = ($config->get('preprocess_css'));
|
||||
$preprocess_css = $config->get('preprocess_css');
|
||||
}
|
||||
|
||||
// For each group that needs aggregation, aggregate its items.
|
||||
|
@ -4375,12 +4374,13 @@ function drupal_group_js($javascript) {
|
|||
* @see drupal_pre_render_scripts()
|
||||
*/
|
||||
function drupal_aggregate_js(&$js_groups) {
|
||||
if (defined('MAINTENANCE_MODE') && (MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update')) {
|
||||
$preprocess_js = FALSE;
|
||||
// Only aggregate during normal site operation.
|
||||
if (defined('MAINTENANCE_MODE')) {
|
||||
$preprocess_js = FALSE;
|
||||
}
|
||||
else {
|
||||
$config = config('system.performance');
|
||||
$preprocess_js = ($config->get('preprocess_js'));
|
||||
$preprocess_js = $config->get('preprocess_js');
|
||||
}
|
||||
|
||||
// Only aggregate when the site is configured to do so, and not during an
|
||||
|
@ -5135,7 +5135,7 @@ function _drupal_bootstrap_full() {
|
|||
function drupal_page_set_cache() {
|
||||
global $base_root;
|
||||
$config = config('system.performance');
|
||||
|
||||
|
||||
if (drupal_page_is_cacheable()) {
|
||||
$cache = (object) array(
|
||||
'cid' => $base_root . request_uri(),
|
||||
|
@ -6559,7 +6559,7 @@ function drupal_array_set_nested_value(array &$array, array $parents, $value, $f
|
|||
* @code array('signature_settings', 'user', 'signature') @endcode in the second
|
||||
* case.
|
||||
*
|
||||
* Without this helper function the only way to unset the signature element in
|
||||
* Without this helper function the only way to unset the signature element in
|
||||
* one line would be using eval(), which should be avoided:
|
||||
* @code
|
||||
* // Do not do this! Avoid eval().
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*/
|
||||
function config_get_config_directory() {
|
||||
global $drupal_config_directory_name;
|
||||
|
||||
|
||||
return conf_path() . '/files/' . $drupal_config_directory_name;
|
||||
}
|
||||
|
||||
|
@ -32,9 +32,8 @@ function config_install_default_config($module) {
|
|||
// Load config data into the active store and write it out to the
|
||||
// file system in the drupal config directory. Note the config name
|
||||
// needs to be the same as the file name WITHOUT the extension.
|
||||
//
|
||||
// @todo Make this acknowledge other storage engines rather than having
|
||||
// SQL be hardcoded.
|
||||
// SQL be hardcoded.
|
||||
$parts = explode('/', $file);
|
||||
$file = array_pop($parts);
|
||||
$config_name = str_replace('.xml', '', $file);
|
||||
|
@ -49,8 +48,8 @@ function config_install_default_config($module) {
|
|||
* Retrieve an iterable array which lists the children under a config 'branch'.
|
||||
*
|
||||
* Given the following configuration files:
|
||||
* core.entity.node_type.article.xml
|
||||
* core.entity.node_type.page.xml
|
||||
* - core.entity.node_type.article.xml
|
||||
* - core.entity.node_type.page.xml
|
||||
*
|
||||
* You can pass a prefix 'core.entity.node_type' and get back an array of the
|
||||
* filenames that match. This allows you to iterate through all files in a
|
||||
|
@ -59,6 +58,7 @@ function config_install_default_config($module) {
|
|||
*
|
||||
* @param $prefix
|
||||
* The prefix of the files we are searching for.
|
||||
*
|
||||
* @return
|
||||
* An array of file names under a branch.
|
||||
*/
|
||||
|
@ -81,9 +81,9 @@ function config_get_signed_file_storage_names_with_prefix($prefix = '') {
|
|||
function config_sign_data($data) {
|
||||
// The configuration key is loaded from settings.php and imported into the global namespace
|
||||
global $drupal_config_key;
|
||||
|
||||
|
||||
// SHA-512 is both secure and very fast on 64 bit CPUs.
|
||||
// TODO: What about 32-bit CPUs?
|
||||
// @todo What about 32-bit CPUs?
|
||||
return hash_hmac('sha512', $data, $drupal_config_key);
|
||||
}
|
||||
|
||||
|
@ -109,12 +109,13 @@ function config_get_names_with_prefix($prefix) {
|
|||
* @param $class
|
||||
* The class name of the config object to be returned. Defaults to
|
||||
* DrupalConfig.
|
||||
*
|
||||
* @return
|
||||
* An instance of the class specified in the $class parameter.
|
||||
*
|
||||
*/
|
||||
function config($name, $class = 'DrupalConfig') {
|
||||
// @TODO Replace this with the appropriate factory.
|
||||
// @todo Replace this with an appropriate factory.
|
||||
return new $class(new DrupalVerifiedStorageSQL($name));
|
||||
}
|
||||
|
||||
|
@ -122,7 +123,8 @@ function config($name, $class = 'DrupalConfig') {
|
|||
* Decode configuration data from its native format to an associative array.
|
||||
*
|
||||
* @param $data
|
||||
* Configuration data
|
||||
* Configuration data.
|
||||
*
|
||||
* @return
|
||||
* An associative array representation of the data.
|
||||
*/
|
||||
|
@ -136,28 +138,26 @@ function config_decode($data) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Helper function for standardizing SimpleXML object output into simple
|
||||
* arrays for easier use.
|
||||
* Standardizes SimpleXML object output into simple arrays for easier use.
|
||||
*
|
||||
* @param $xmlObject
|
||||
* A valid XML string.
|
||||
* A valid XML string.
|
||||
*
|
||||
* @return
|
||||
* An array representation of A SimpleXML object.
|
||||
* An array representation of A SimpleXML object.
|
||||
*/
|
||||
function config_xml_to_array($data) {
|
||||
$out = array();
|
||||
$xmlObject = simplexml_load_string($data);
|
||||
|
||||
|
||||
if (is_object($xmlObject)) {
|
||||
$attributes = (array)$xmlObject->attributes();
|
||||
$attributes = (array) $xmlObject->attributes();
|
||||
if (isset($attributes['@attributes'])) {
|
||||
$out['#attributes'] = $attributes['@attributes'];
|
||||
}
|
||||
}
|
||||
if (trim((string)$xmlObject)) {
|
||||
$out = trim((string)$xmlObject);
|
||||
return $out;
|
||||
if (trim((string) $xmlObject)) {
|
||||
return trim((string) $xmlObject);
|
||||
}
|
||||
foreach ($xmlObject as $index => $content) {
|
||||
if (is_object($content)) {
|
||||
|
@ -217,7 +217,7 @@ function config_array_to_xml($array, &$xml_object) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
$xml_object->addChild("$key","$value");
|
||||
$xml_object->addChild("$key", "$value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ class SignedFileStorage {
|
|||
* Exception
|
||||
*/
|
||||
protected function readWithSignature() {
|
||||
// TODO: Optimize with explicit offsets?
|
||||
// @todo Optimize with explicit offsets?
|
||||
$content = file_get_contents($this->getFilePath());
|
||||
if ($content === FALSE) {
|
||||
throw new Exception('Read file is invalid.');
|
||||
|
@ -298,6 +298,7 @@ class SignedFileStorage {
|
|||
*
|
||||
* @param $contentOnSuccess
|
||||
* Whether or not to return the contents of the verified configuration file.
|
||||
*
|
||||
* @return mixed
|
||||
* If $contentOnSuccess was TRUE, returns the contents of the verified
|
||||
* configuration file; otherwise returns TRUE on success. Always returns
|
||||
|
@ -321,7 +322,8 @@ class SignedFileStorage {
|
|||
* Writes the contents of the configuration file to disk.
|
||||
*
|
||||
* @param $data
|
||||
* The data to be written to the file. // TODO - what format is it in?
|
||||
* The data to be written to the file.
|
||||
* @todo What format is $data in?
|
||||
*
|
||||
* @throws
|
||||
* Exception
|
||||
|
@ -348,7 +350,7 @@ class SignedFileStorage {
|
|||
return $verification;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a configuration file.
|
||||
*/
|
||||
|
@ -368,7 +370,7 @@ interface DrupalConfigVerifiedStorageInterface {
|
|||
* verified storage and copying to/from the signed file storing the same
|
||||
* data.
|
||||
*
|
||||
* param @name
|
||||
* @param @name
|
||||
* Lowercase string, the name for the configuration data.
|
||||
*/
|
||||
function __construct($name);
|
||||
|
@ -467,8 +469,8 @@ abstract class DrupalConfigVerifiedStorage implements DrupalConfigVerifiedStorag
|
|||
class DrupalVerifiedStorageSQL extends DrupalConfigVerifiedStorage {
|
||||
|
||||
public function read() {
|
||||
// There are situations, like in the installer, where we may attempt a
|
||||
// read without actually having the database available. This is a
|
||||
// There are situations, like in the installer, where we may attempt a
|
||||
// read without actually having the database available. This is a
|
||||
// workaround and there is probably a better solution to be had at
|
||||
// some point.
|
||||
if (!empty($GLOBALS['databases']) && db_table_exists('config')) {
|
||||
|
@ -518,7 +520,7 @@ class DrupalConfig {
|
|||
$this->_verifiedStorage = $verified_storage;
|
||||
$this->read();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read config data from the active store into our object.
|
||||
*/
|
||||
|
@ -526,7 +528,7 @@ class DrupalConfig {
|
|||
$active = (array) config_decode($this->_verifiedStorage->read());
|
||||
foreach ($active as $key => $value) {
|
||||
$this->set($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -992,12 +992,12 @@ function install_settings_form_submit($form, &$form_state) {
|
|||
'value' => drupal_hash_base64(drupal_random_bytes(55)),
|
||||
'required' => TRUE,
|
||||
);
|
||||
|
||||
|
||||
$settings['drupal_config_key'] = array(
|
||||
'value' => drupal_hash_base64(drupal_random_bytes(55)),
|
||||
'required' => TRUE,
|
||||
);
|
||||
|
||||
|
||||
// This duplicates drupal_get_token() because that function can't work yet.
|
||||
// Wondering if it makes sense to move this later in the process, but its
|
||||
// nice having all the settings stuff here.
|
||||
|
@ -1010,7 +1010,7 @@ function install_settings_form_submit($form, &$form_state) {
|
|||
'value' => 'config_' . drupal_hmac_base64('', session_id() . $settings['drupal_config_key']['value'] . $settings['drupal_hash_salt']['value']),
|
||||
'required' => TRUE,
|
||||
);
|
||||
|
||||
|
||||
drupal_rewrite_settings($settings);
|
||||
// Actually create the config directory named above.
|
||||
$config_path = conf_path() . '/files/' . $settings['drupal_config_directory_name']['value'];
|
||||
|
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Tests for config.module.
|
||||
* Tests for Configuration module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test cases for the secure file writer.
|
||||
*/
|
||||
class SecureFileTestCase extends DrupalUnitTestCase {
|
||||
protected $filename = 'foo.bar';
|
||||
|
||||
protected $testContent = 'Good morning, Denver!';
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Secure file tests',
|
||||
|
@ -17,73 +21,65 @@ class SecureFileTestCase extends DrupalUnitTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected $filename = 'foo.bar';
|
||||
|
||||
protected $testContent = 'Good morning, Denver!';
|
||||
|
||||
/**
|
||||
* Tests that a file written by this system has a valid signature.
|
||||
*/
|
||||
public function testFileVerify() {
|
||||
function testFileVerify() {
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$file->write($this->testContent);
|
||||
|
||||
$this->assertTrue($file->verify(), t('A file verifies after being written.'));
|
||||
$this->assertTrue($file->verify(), 'A file verifies after being written.');
|
||||
|
||||
unset($file);
|
||||
|
||||
// Load the file again, so that there is no stale data from the old object.
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$this->assertTrue($file->verify(), t('A file verifies after being written and reloaded.'));
|
||||
$this->assertTrue($file->verify(), 'A file verifies after being written and reloaded.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a file written by this system can be successfully read back.
|
||||
*/
|
||||
public function testFilePersist() {
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$file->write($this->testContent);
|
||||
function testFilePersist() {
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$file->write($this->testContent);
|
||||
|
||||
unset($file);
|
||||
unset($file);
|
||||
|
||||
// Reading should throw an exception in case of bad validation.
|
||||
// Note that if any other exception is thrown, we let the test system
|
||||
// handle catching and reporting it.
|
||||
try {
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$saved_content = $file->read();
|
||||
// Reading should throw an exception in case of bad validation.
|
||||
// Note that if any other exception is thrown, we let the test system
|
||||
// handle catching and reporting it.
|
||||
try {
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$saved_content = $file->read();
|
||||
|
||||
$this->assertEqual($saved_content, $this->testContent, t('A file can be read back successfully.'));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->fail(t('File failed verification when being read.'));
|
||||
}
|
||||
}
|
||||
$this->assertEqual($saved_content, $this->testContent, 'A file can be read back successfully.');
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->fail('File failed verification when being read.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a file fails validation if it's been monkeyed with.
|
||||
*/
|
||||
public function testFileNotVerify() {
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$file->write($this->testContent);
|
||||
/**
|
||||
* Tests that a file fails validation if it's been monkeyed with.
|
||||
*/
|
||||
function testFileNotVerify() {
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$file->write($this->testContent);
|
||||
|
||||
// Manually overwrite the body of the secure file. Note that we skip the
|
||||
// first line, which is reserved for the signature and such, to overwrite
|
||||
// just the payload.
|
||||
$raw_file = new SplFileObject($file->getFilePath(), 'a+');
|
||||
$raw_file->fwrite('Good morning, Detroit!');
|
||||
$raw_file->fflush();
|
||||
unset($raw_file);
|
||||
// Manually overwrite the body of the secure file. Note that we skip the
|
||||
// first line, which is reserved for the signature and such, to overwrite
|
||||
// just the payload.
|
||||
$raw_file = new SplFileObject($file->getFilePath(), 'a+');
|
||||
$raw_file->fwrite('Good morning, Detroit!');
|
||||
$raw_file->fflush();
|
||||
unset($raw_file);
|
||||
|
||||
unset($file);
|
||||
unset($file);
|
||||
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$this->assertFalse($file->verify(), t('Corrupted file does not verify.'));
|
||||
}
|
||||
$file = new SignedFileStorage($this->filename);
|
||||
$this->assertFalse($file->verify(), 'Corrupted file does not verify.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,10 +94,6 @@ class FileContentsTestCase extends DrupalWebTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a simple setting can be written and read.
|
||||
*/
|
||||
|
@ -109,6 +101,6 @@ class FileContentsTestCase extends DrupalWebTestCase {
|
|||
$config = config('foo.bar');
|
||||
$config->foo = 'bar';
|
||||
$config->save();
|
||||
$this->assertEqual('bar', config('foo.bar')->foo, t('Content retrived from written config data.'));
|
||||
$this->assertEqual('bar', config('foo.bar')->foo, 'Content retrived from written config data.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,4 +13,4 @@
|
|||
<weight>0</weight>
|
||||
</image_scale_480_480_1>
|
||||
</effects>
|
||||
</config>
|
||||
</config>
|
||||
|
|
|
@ -13,4 +13,4 @@
|
|||
<weight>0</weight>
|
||||
</image_scale_220_220_1>
|
||||
</effects>
|
||||
</config>
|
||||
</config>
|
||||
|
|
|
@ -13,4 +13,4 @@
|
|||
<weight>0</weight>
|
||||
</image_scale_100_100_1>
|
||||
</effects>
|
||||
</config>
|
||||
</config>
|
||||
|
|
|
@ -119,7 +119,7 @@ function image_style_form($form, &$form_state, $style) {
|
|||
'#validate' => array('image_style_form_add_validate'),
|
||||
'#submit' => array('image_style_form_submit', 'image_style_form_add_submit'),
|
||||
);
|
||||
|
||||
|
||||
// Show the Override or Submit button for this style.
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
|
@ -158,7 +158,7 @@ function image_style_form_add_submit($form, &$form_state) {
|
|||
'name' => $effect['name'],
|
||||
'data' => array(),
|
||||
'weight' => $form_state['values']['weight'],
|
||||
);
|
||||
);
|
||||
image_effect_save($style['name'], $effect);
|
||||
drupal_set_message(t('The image effect was successfully applied.'));
|
||||
}
|
||||
|
@ -178,15 +178,15 @@ function image_style_form_submit($form, &$form_state) {
|
|||
'name' => $style['effects'][$ieid]['name'],
|
||||
'data' => $style['effects'][$ieid]['data'],
|
||||
'weight' => $effect_data['weight'],
|
||||
);
|
||||
);
|
||||
$style['effects'][$ieid] = $effect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the image style name if it has changed. We also need to delete the
|
||||
// old style, because there is no concept of rename at the moment, just
|
||||
// create and delete.
|
||||
// old style, because there is no concept of rename at the moment, just
|
||||
// create and delete.
|
||||
if (isset($form_state['values']['name']) && $style['name'] != $form_state['values']['name']) {
|
||||
image_style_delete($style);
|
||||
$style['name'] = $form_state['values']['name'];
|
||||
|
@ -628,7 +628,6 @@ function theme_image_style_list($variables) {
|
|||
*/
|
||||
function theme_image_style_effects($variables) {
|
||||
$form = $variables['form'];
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach (element_children($form) as $key) {
|
||||
|
|
|
@ -436,7 +436,7 @@ function image_path_flush($path) {
|
|||
*/
|
||||
function image_styles() {
|
||||
$styles = &drupal_static(__FUNCTION__);
|
||||
|
||||
|
||||
// Grab from cache or build the array.
|
||||
if (!isset($styles)) {
|
||||
if ($cache = cache()->get('image_styles')) {
|
||||
|
@ -505,7 +505,7 @@ function image_style_save($style) {
|
|||
$config->set('effects', $style['effects']);
|
||||
}
|
||||
else {
|
||||
$config->set('effects', array());
|
||||
$config->set('effects', array());
|
||||
}
|
||||
$config->save();
|
||||
$style['is_new'] = TRUE;
|
||||
|
@ -983,9 +983,9 @@ function image_effect_save($style_name, $effect) {
|
|||
else {
|
||||
// We need to generate the ieid and save the new effect.
|
||||
// The machine name is all the elements of the data array concatenated
|
||||
// together, delimited by underscores.
|
||||
// together, delimited by underscores.
|
||||
$machine_name = $effect['name'];
|
||||
|
||||
|
||||
foreach ($effect['data'] as $key => $value) {
|
||||
$machine_name .= '_' . $value;
|
||||
}
|
||||
|
|
|
@ -1719,8 +1719,8 @@ function system_performance_settings($form, &$form_state) {
|
|||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save configuration')
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save configuration'),
|
||||
);
|
||||
|
||||
$form['#submit'][] = 'drupal_clear_css_cache';
|
||||
|
|
|
@ -239,20 +239,19 @@ $drupal_hash_salt = '';
|
|||
*
|
||||
* By default, Drupal configuration files are stored in a randomly named
|
||||
* directory under the default public files path. On install the
|
||||
* named directory is created in the default files directory. For enhanced
|
||||
* named directory is created in the default files directory. For enhanced
|
||||
* security, you may set this variable to a location outside your docroot.
|
||||
*
|
||||
* @todo flesh this out, provide more details, etc.
|
||||
* @todo Flesh this out, provide more details, etc.
|
||||
*
|
||||
* Example:
|
||||
* $drupal_config_directory_name = '/some/directory/outside/webroot';
|
||||
*
|
||||
*/
|
||||
$drupal_config_directory_name = '';
|
||||
|
||||
/**
|
||||
* Configuration key.
|
||||
*
|
||||
*
|
||||
* Drupal configuration files are signed using this key.
|
||||
*/
|
||||
$drupal_config_key = '';
|
||||
|
|
Loading…
Reference in New Issue