Commit 51cf18e5 authored by Steven Wittens's avatar Steven Wittens

- #9292: Make Drupal (somewhat) PHP5 compatible. xtemplate is still horribly broken.

parent 95cb7f32
......@@ -399,10 +399,10 @@ function drupal_http_request($url, $headers = array(), $method = 'GET', $data =
* Log errors in the database rather than displaying them to the user.
*/
function error_handler($errno, $message, $filename, $line, $variables) {
$types = array(1 => 'error', 2 => 'warning', 4 => 'parse error', 8 => 'notice', 16 => 'core error', 32 => 'core warning', 64 => 'compile error', 128 => 'compile warning', 256 => 'user error', 512 => 'user warning', 1024 => 'user notice');
$types = array(1 => 'error', 2 => 'warning', 4 => 'parse error', 8 => 'notice', 16 => 'core error', 32 => 'core warning', 64 => 'compile error', 128 => 'compile warning', 256 => 'user error', 512 => 'user warning', 1024 => 'user notice', 2048 => 'strict warning');
$entry = $types[$errno] .': '. $message .' in '. $filename .' on line '. $line .'.';
if ($errno & E_ALL ^ E_NOTICE) {
if ($errno & (E_ALL ^ E_NOTICE)) {
watchdog('error', t('%error: %message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line)));
if (error_reporting()) {
print '<pre>'. $entry .'</pre>';
......@@ -446,6 +446,7 @@ function fix_gpc_magic() {
*/
function array2object($array) {
if (is_array($array)) {
$object = new stdClass();
foreach ($array as $key => $value) {
$object->$key = $value;
}
......
......@@ -442,6 +442,7 @@ function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $ca
}
elseif (ereg($mask, $file)) {
$name = basename($file);
$files["$dir/$file"] = new stdClass();
$files["$dir/$file"]->filename = "$dir/$file";
$files["$dir/$file"]->name = substr($name, 0, strrpos($name, '.'));
if ($callback) {
......
......@@ -238,9 +238,12 @@ function module_invoke_all($hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL
$return = array();
foreach (module_list() as $module) {
$result = module_invoke($module, $hook, $a1, $a2, $a3, $a4);
if (isset($result)) {
if (is_array($result)) {
$return = array_merge($return, $result);
}
else if (isset($result)) {
$return[] = $result;
}
}
return $return;
......
......@@ -365,7 +365,10 @@ function block_list($region) {
** based on server load.
*/
if (!($block['throttle'] && (module_invoke('throttle', 'status') > 4))) {
$block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
$array = module_invoke($block['module'], 'block', 'view', $block['delta']);
if (is_array($array)) {
$block = array_merge($block, $array);
}
}
if (isset($block['content']) && $block['content']) {
$blocks[$region]["$block[module]_$block[delta]"] = (object) $block;
......
......@@ -365,7 +365,10 @@ function block_list($region) {
** based on server load.
*/
if (!($block['throttle'] && (module_invoke('throttle', 'status') > 4))) {
$block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
$array = module_invoke($block['module'], 'block', 'view', $block['delta']);
if (is_array($array)) {
$block = array_merge($block, $array);
}
}
if (isset($block['content']) && $block['content']) {
$blocks[$region]["$block[module]_$block[delta]"] = (object) $block;
......
......@@ -502,6 +502,7 @@ function comment_preview($edit) {
$output = '';
$comment = new StdClass();
foreach ($edit as $key => $value) {
$comment->$key = $value;
}
......
......@@ -502,6 +502,7 @@ function comment_preview($edit) {
$output = '';
$comment = new StdClass();
foreach ($edit as $key => $value) {
$comment->$key = $value;
}
......
......@@ -157,6 +157,7 @@ function forum_link($type, $node = 0, $main = 0) {
while ($topic = db_fetch_object($result)) {
if ($stop == 1) {
$next = new StdClass();
$next->nid = $topic->nid;
$next->title = $topic->title;
break;
......@@ -311,7 +312,12 @@ function _forum_last_comment($nid) {
function _forum_last_reply($nid) {
$value = db_fetch_object(db_query_range('SELECT c.timestamp, c.name AS anonymous_name, u.name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.timestamp DESC', $nid, 0, 1));
$value->name = $value->uid ? $value->name : $value->anonymous_name;
if ($value) {
$value->name = $value->uid ? $value->name : $value->anonymous_name;
}
else {
$value = new StdClass();
}
return $value;
}
......@@ -373,9 +379,13 @@ function _forum_topics_read($term, $uid) {
function _forum_last_post($term) {
$topic = db_fetch_object(db_query_range("SELECT DISTINCT(n.nid), n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid ". node_access_join_sql() ." INNER JOIN {users} u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." ORDER BY timestamp DESC", $term, 0, 1));
$reply = db_fetch_object(db_query_range("SELECT DISTINCT(n.nid), c.timestamp, c.name AS anonymous_name, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid ". node_access_join_sql() ." INNER JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." AND c.status = 0 ORDER BY c.timestamp DESC", $term, 0, 1));
$reply->name = $reply->uid ? $reply->name : $reply->anonymous_name;
if ($reply) {
$reply->name = $reply->uid ? $reply->name : $reply->anonymous_name;
}
else {
$reply = new StdClass();
}
$value = ($topic->timestamp > $reply->timestamp) ? $topic : $reply;
......
......@@ -157,6 +157,7 @@ function forum_link($type, $node = 0, $main = 0) {
while ($topic = db_fetch_object($result)) {
if ($stop == 1) {
$next = new StdClass();
$next->nid = $topic->nid;
$next->title = $topic->title;
break;
......@@ -311,7 +312,12 @@ function _forum_last_comment($nid) {
function _forum_last_reply($nid) {
$value = db_fetch_object(db_query_range('SELECT c.timestamp, c.name AS anonymous_name, u.name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.timestamp DESC', $nid, 0, 1));
$value->name = $value->uid ? $value->name : $value->anonymous_name;
if ($value) {
$value->name = $value->uid ? $value->name : $value->anonymous_name;
}
else {
$value = new StdClass();
}
return $value;
}
......@@ -373,9 +379,13 @@ function _forum_topics_read($term, $uid) {
function _forum_last_post($term) {
$topic = db_fetch_object(db_query_range("SELECT DISTINCT(n.nid), n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid ". node_access_join_sql() ." INNER JOIN {users} u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." ORDER BY timestamp DESC", $term, 0, 1));
$reply = db_fetch_object(db_query_range("SELECT DISTINCT(n.nid), c.timestamp, c.name AS anonymous_name, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid ". node_access_join_sql() ." INNER JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." AND c.status = 0 ORDER BY c.timestamp DESC", $term, 0, 1));
$reply->name = $reply->uid ? $reply->name : $reply->anonymous_name;
if ($reply) {
$reply->name = $reply->uid ? $reply->name : $reply->anonymous_name;
}
else {
$reply = new StdClass();
}
$value = ($topic->timestamp > $reply->timestamp) ? $topic : $reply;
......
......@@ -347,9 +347,12 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$function = $name .'_nodeapi';
if (function_exists($function)) {
$result = $function($node, $op, $a3, $a4);
if (isset($result)) {
if (is_array($result)) {
$return = array_merge($return, $result);
}
else {
$return[] = $result;
}
}
}
return $return;
......@@ -397,7 +400,7 @@ function node_load($conditions, $revision = -1) {
}
// Return the desired revision.
if ($revision != -1 && isset($node->revisions[$revision])) {
if ($revision != -1 && is_array($node->revisions[$revision])) {
$node = $node->revisions[$revision]['node'];
}
......@@ -814,6 +817,7 @@ function node_default_settings() {
$header = array_merge(array(t('type')), array_keys(node_invoke_nodeapi($node, 'settings')));
foreach (node_list() as $type) {
$node = new StdClass();
$node->type = $type;
$cols = array();
foreach (node_invoke_nodeapi($node, 'settings') as $setting) {
......@@ -1221,7 +1225,11 @@ function node_form($edit) {
}
}
return form($output, ($param['method'] ? $param['method'] : 'post'), $param['action'], array_merge($param['options'], array('id' => 'node-form')));
$attributes = array('id' => 'node-form');
if (is_array($param['options'])) {
$attributes = array_merge($param['options'], $attributes);
}
return form($output, ($param['method'] ? $param['method'] : 'post'), $param['action'], $attributes);
}
/**
......
......@@ -347,9 +347,12 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$function = $name .'_nodeapi';
if (function_exists($function)) {
$result = $function($node, $op, $a3, $a4);
if (isset($result)) {
if (is_array($result)) {
$return = array_merge($return, $result);
}
else {
$return[] = $result;
}
}
}
return $return;
......@@ -397,7 +400,7 @@ function node_load($conditions, $revision = -1) {
}
// Return the desired revision.
if ($revision != -1 && isset($node->revisions[$revision])) {
if ($revision != -1 && is_array($node->revisions[$revision])) {
$node = $node->revisions[$revision]['node'];
}
......@@ -814,6 +817,7 @@ function node_default_settings() {
$header = array_merge(array(t('type')), array_keys(node_invoke_nodeapi($node, 'settings')));
foreach (node_list() as $type) {
$node = new StdClass();
$node->type = $type;
$cols = array();
foreach (node_invoke_nodeapi($node, 'settings') as $setting) {
......@@ -1221,7 +1225,11 @@ function node_form($edit) {
}
}
return form($output, ($param['method'] ? $param['method'] : 'post'), $param['action'], array_merge($param['options'], array('id' => 'node-form')));
$attributes = array('id' => 'node-form');
if (is_array($param['options'])) {
$attributes = array_merge($param['options'], $attributes);
}
return form($output, ($param['method'] ? $param['method'] : 'post'), $param['action'], $attributes);
}
/**
......
......@@ -54,14 +54,19 @@ function user_load($array = array()) {
}
$result = db_query_range("SELECT u.* FROM {users} u WHERE $query u.status < 3", 0, 1);
$user = db_fetch_object($result);
$user = drupal_unpack($user);
user_module_invoke('load', $array, $user);
if (db_num_rows($result)) {
$user = db_fetch_object($result);
$user = drupal_unpack($user);
user_module_invoke('load', $array, $user);
$user->roles = array();
$result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
while ($role = db_fetch_object($result)) {
$user->roles[$role->rid] = $role->name;
$user->roles = array();
$result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
while ($role = db_fetch_object($result)) {
$user->roles[$role->rid] = $role->name;
}
}
else {
$user = new StdClass();
}
return $user;
......
......@@ -54,14 +54,19 @@ function user_load($array = array()) {
}
$result = db_query_range("SELECT u.* FROM {users} u WHERE $query u.status < 3", 0, 1);
$user = db_fetch_object($result);
$user = drupal_unpack($user);
user_module_invoke('load', $array, $user);
if (db_num_rows($result)) {
$user = db_fetch_object($result);
$user = drupal_unpack($user);
user_module_invoke('load', $array, $user);
$user->roles = array();
$result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
while ($role = db_fetch_object($result)) {
$user->roles[$role->rid] = $role->name;
$user->roles = array();
$result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
while ($role = db_fetch_object($result)) {
$user->roles[$role->rid] = $role->name;
}
}
else {
$user = new StdClass();
}
return $user;
......
......@@ -129,6 +129,7 @@ function chameleon_node($node, $main = 0, $page = 0) {
$submitted = theme_get_setting("toggle_node_info_$node->type") ? array(t("By %author at %date", array('%author' => format_name($node), '%date' => format_date($node->created, 'small')))) : array();
$terms = array();
if (module_exist('taxonomy')) {
$terms = taxonomy_link("taxonomy terms", $node);
}
......
......@@ -12,6 +12,7 @@ function xtemplate_init($template) {
if (!class_exists('XTemplate')) {
include_once('themes/engines/xtemplate/xtemplate.inc');
}
$GLOBALS["xtemplate"] = new StdClass();
$GLOBALS['xtemplate']->template = new XTemplate(basename($template->filename), dirname($template->filename));
$GLOBALS['xtemplate']->template->SetNullBlock(' '); // '' doesnt work!
}
......
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