Commit ea2d7910 authored by Dries's avatar Dries

- Patch 41169 by Chris: got rid of expensvie object 2 array casts.

parent 9ff2c1b3
......@@ -489,50 +489,6 @@ function fix_gpc_magic() {
}
}
/**
* @name Conversion
* @{
* Converts data structures to different types.
*/
/**
* Convert an associative array to an anonymous object.
*/
function array2object($array) {
if (is_array($array)) {
$object = new StdClass();
foreach ($array as $key => $value) {
$object->$key = $value;
}
}
else {
$object = $array;
}
return $object;
}
/**
* Convert an object to an associative array.
*/
function object2array($object) {
if (is_object($object)) {
foreach ($object as $key => $value) {
$array[$key] = $value;
}
}
else {
$array = $object;
}
return $array;
}
/**
* @} End of "Conversion".
*/
/**
* @name Messages
* @{
......
......@@ -294,7 +294,7 @@ function stopEvent(event) {
else {
event.returnValue = false;
event.cancelBubble = true;
}
}
}
/**
......
......@@ -6,7 +6,7 @@ if (isJsEnabled()) {
for (var i = 0; textarea = textareas[i]; ++i) {
if (hasClass(textarea, 'resizable')) {
if (typeof dimensions(textarea).width != 'undefined' && dimensions(textarea).width != 0) {
new textArea(textarea);
new textArea(textarea);
}
}
}
......@@ -18,7 +18,7 @@ function textArea(element) {
this.element = element;
this.parent = this.element.parentNode;
this.dimensions = dimensions(element);
// Prepare wrapper
this.wrapper = document.createElement('div');
this.wrapper.className = 'resizable-textarea';
......@@ -56,7 +56,7 @@ function textArea(element) {
this.grippie.style.paddingLeft = '2px';
}
// Mozilla
this.element.style.MozBoxSizing = 'border-box';
this.element.style.MozBoxSizing = 'border-box';
this.heightOffset = absolutePosition(this.grippie).y - absolutePosition(this.element).y - this.dimensions.height;
}
......
......@@ -629,7 +629,7 @@ function blogapi_rsd() {
function _blogapi_mt_extra(&$node, $struct) {
if (is_array($node)) {
$was_array = true;
$node = array2object($node);
$node = (object)$node;
}
// mt_allow_comments
......@@ -681,7 +681,7 @@ function _blogapi_mt_extra(&$node, $struct) {
}
if ($was_array) {
$node = object2array($node);
$node = (array)$node;
}
}
......
......@@ -629,7 +629,7 @@ function blogapi_rsd() {
function _blogapi_mt_extra(&$node, $struct) {
if (is_array($node)) {
$was_array = true;
$node = array2object($node);
$node = (object)$node;
}
// mt_allow_comments
......@@ -681,7 +681,7 @@ function _blogapi_mt_extra(&$node, $struct) {
}
if ($was_array) {
$node = object2array($node);
$node = (array)$node;
}
}
......
......@@ -444,7 +444,7 @@ function comment_edit($cid) {
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (comment_access('edit', $comment)) {
return comment_form(object2array($comment));
return comment_form((array)$comment);
}
else {
drupal_access_denied();
......@@ -1349,7 +1349,7 @@ function comment_form_add_preview($form, $edit) {
$output = '';
$comment = array2object(comment_validate($edit));
$comment = (object)comment_validate($edit);
// Attach the user and time information.
if ($edit['author']) {
......
......@@ -444,7 +444,7 @@ function comment_edit($cid) {
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (comment_access('edit', $comment)) {
return comment_form(object2array($comment));
return comment_form((array)$comment);
}
else {
drupal_access_denied();
......@@ -1349,7 +1349,7 @@ function comment_form_add_preview($form, $edit) {
$output = '';
$comment = array2object(comment_validate($edit));
$comment = (object)comment_validate($edit);
// Attach the user and time information.
if ($edit['author']) {
......
......@@ -105,10 +105,10 @@ function forum_admin() {
break;
case 'edit':
if (arg(3) == 'forum') {
$output = forum_form_forum(object2array(taxonomy_get_term(arg(4))));
$output = forum_form_forum((array)taxonomy_get_term(arg(4)));
}
else if (arg(3) == 'container') {
$output = forum_form_container(object2array(taxonomy_get_term(arg(4))));
$output = forum_form_container((array)taxonomy_get_term(arg(4)));
}
break;
case t('Delete'):
......
......@@ -105,10 +105,10 @@ function forum_admin() {
break;
case 'edit':
if (arg(3) == 'forum') {
$output = forum_form_forum(object2array(taxonomy_get_term(arg(4))));
$output = forum_form_forum((array)taxonomy_get_term(arg(4)));
}
else if (arg(3) == 'container') {
$output = forum_form_container(object2array(taxonomy_get_term(arg(4))));
$output = forum_form_container((array)taxonomy_get_term(arg(4)));
}
break;
case t('Delete'):
......
......@@ -513,7 +513,7 @@ function node_save(&$node) {
* An HTML representation of the themed node.
*/
function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
$node = array2object($node);
$node = (object)$node;
// Remove the delimiter (if any) that separates the teaser from the body.
// TODO: this strips legitimate uses of '<!--break-->' also.
......@@ -1493,7 +1493,7 @@ function node_submit($node) {
global $user;
// Convert the node to an object, if necessary.
$node = array2object($node);
$node = (object)$node;
// Auto-generate the teaser, but only if it hasn't been set (e.g. by a
// module-provided 'teaser' form item).
......@@ -1539,7 +1539,7 @@ function node_submit($node) {
*/
function node_validate($node) {
// Convert the node to an object, if necessary.
$node = array2object($node);
$node = (object)$node;
// Make sure the body has the minimum number of words.
// todo use a better word counting algorithm that will work in other languages
......@@ -1609,7 +1609,7 @@ function node_object_prepare(&$node) {
function node_form($node) {
$op = isset($_POST['op']) ? $_POST['op'] : '';
$node = array2object($node);
$node = (object)$node;
node_object_prepare($node);
// Set the id of the top-level form tag
......@@ -1693,7 +1693,7 @@ function node_form($node) {
}
function node_form_add_preview($form, $edit) {
$edit = array2object($edit);
$edit = (object)$edit;
node_validate($edit);
$form['node_preview'] = array('#value' => node_preview($edit), '#weight' => -100);
return $form;
......@@ -2167,7 +2167,7 @@ function node_form_alter($form_id, &$form) {
*/
function node_access($op, $node = NULL, $uid = NULL) {
// Convert the node to an object if necessary:
$node = array2object($node);
$node = (object)$node;
// If the node is in a restricted format, disallow editing.
if ($op == 'update' && !filter_access($node->format)) {
......
......@@ -513,7 +513,7 @@ function node_save(&$node) {
* An HTML representation of the themed node.
*/
function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
$node = array2object($node);
$node = (object)$node;
// Remove the delimiter (if any) that separates the teaser from the body.
// TODO: this strips legitimate uses of '<!--break-->' also.
......@@ -1493,7 +1493,7 @@ function node_submit($node) {
global $user;
// Convert the node to an object, if necessary.
$node = array2object($node);
$node = (object)$node;
// Auto-generate the teaser, but only if it hasn't been set (e.g. by a
// module-provided 'teaser' form item).
......@@ -1539,7 +1539,7 @@ function node_submit($node) {
*/
function node_validate($node) {
// Convert the node to an object, if necessary.
$node = array2object($node);
$node = (object)$node;
// Make sure the body has the minimum number of words.
// todo use a better word counting algorithm that will work in other languages
......@@ -1609,7 +1609,7 @@ function node_object_prepare(&$node) {
function node_form($node) {
$op = isset($_POST['op']) ? $_POST['op'] : '';
$node = array2object($node);
$node = (object)$node;
node_object_prepare($node);
// Set the id of the top-level form tag
......@@ -1693,7 +1693,7 @@ function node_form($node) {
}
function node_form_add_preview($form, $edit) {
$edit = array2object($edit);
$edit = (object)$edit;
node_validate($edit);
$form['node_preview'] = array('#value' => node_preview($edit), '#weight' => -100);
return $form;
......@@ -2167,7 +2167,7 @@ function node_form_alter($form_id, &$form) {
*/
function node_access($op, $node = NULL, $uid = NULL) {
// Convert the node to an object if necessary:
$node = array2object($node);
$node = (object)$node;
// If the node is in a restricted format, disallow editing.
if ($op == 'update' && !filter_access($node->format)) {
......
......@@ -1126,10 +1126,10 @@ function taxonomy_admin() {
break;
case 'edit':
if (arg(3) == 'vocabulary') {
$output = taxonomy_form_vocabulary(object2array(taxonomy_get_vocabulary(arg(4))));
$output = taxonomy_form_vocabulary((array)taxonomy_get_vocabulary(arg(4)));
}
else if (arg(3) == 'term') {
$output = taxonomy_form_term(object2array(taxonomy_get_term(arg(4))));
$output = taxonomy_form_term((array)taxonomy_get_term(arg(4)));
}
break;
case t('Delete'):
......
......@@ -1126,10 +1126,10 @@ function taxonomy_admin() {
break;
case 'edit':
if (arg(3) == 'vocabulary') {
$output = taxonomy_form_vocabulary(object2array(taxonomy_get_vocabulary(arg(4))));
$output = taxonomy_form_vocabulary((array)taxonomy_get_vocabulary(arg(4)));
}
else if (arg(3) == 'term') {
$output = taxonomy_form_term(object2array(taxonomy_get_term(arg(4))));
$output = taxonomy_form_term((array)taxonomy_get_term(arg(4)));
}
break;
case t('Delete'):
......
......@@ -536,7 +536,7 @@ function _upload_image($file) {
*/
function upload_js() {
// We only do the upload.module part of the node validation process.
$node = array2object($_POST['edit']);
$node = (object)$_POST['edit'];
upload_nodeapi($node, 'validate', NULL);
$form = _upload_form($node);
$form = _form_builder('upload_js', $form);
......
......@@ -536,7 +536,7 @@ function _upload_image($file) {
*/
function upload_js() {
// We only do the upload.module part of the node validation process.
$node = array2object($_POST['edit']);
$node = (object)$_POST['edit'];
upload_nodeapi($node, 'validate', NULL);
$form = _upload_form($node);
$form = _form_builder('upload_js', $form);
......
......@@ -1177,7 +1177,7 @@ function user_edit_form($uid, $edit) {
// Picture/avatar:
if (variable_get('user_pictures', 0)) {
$form['picture'] = array('#type' => 'fieldset', '#title' => t('Picture'), '#weight' => 1);
if ($edit['picture'] && ($picture = theme('user_picture', array2object($edit)))) {
if ($edit['picture'] && ($picture = theme('user_picture', (object)$edit))) {
$form['picture']['current_picture'] = array('#type' => 'markup', '#value' => $picture);
$form['picture']['picture_delete'] = array('#type' => 'checkbox', '#title' => t('Delete picture'), '#description' => t('Check this box to delete your current picture.'));
}
......@@ -1257,7 +1257,7 @@ function user_edit($category = 'account') {
global $user;
$account = user_load(array('uid' => arg(1)));
$edit = $_POST['op'] ? $_POST['edit'] : object2array($account);
$edit = $_POST['op'] ? $_POST['edit'] : (array)$account;
if (arg(2) == 'delete') {
if ($edit['confirm']) {
......
......@@ -1177,7 +1177,7 @@ function user_edit_form($uid, $edit) {
// Picture/avatar:
if (variable_get('user_pictures', 0)) {
$form['picture'] = array('#type' => 'fieldset', '#title' => t('Picture'), '#weight' => 1);
if ($edit['picture'] && ($picture = theme('user_picture', array2object($edit)))) {
if ($edit['picture'] && ($picture = theme('user_picture', (object)$edit))) {
$form['picture']['current_picture'] = array('#type' => 'markup', '#value' => $picture);
$form['picture']['picture_delete'] = array('#type' => 'checkbox', '#title' => t('Delete picture'), '#description' => t('Check this box to delete your current picture.'));
}
......@@ -1257,7 +1257,7 @@ function user_edit($category = 'account') {
global $user;
$account = user_load(array('uid' => arg(1)));
$edit = $_POST['op'] ? $_POST['edit'] : object2array($account);
$edit = $_POST['op'] ? $_POST['edit'] : (array)$account;
if (arg(2) == 'delete') {
if ($edit['confirm']) {
......
......@@ -244,7 +244,7 @@ function phptemplate_node($node, $teaser = 0, $page = 0) {
);
// Flatten the node object's member fields.
$variables = array_merge(object2array($node), $variables);
$variables = array_merge((array)$node, $variables);
// Display info only on certain node types.
if (theme_get_setting('toggle_node_info_' . $node->type)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment