Commit 9986cb36 authored by Dries's avatar Dries

- Patch #8973 by JonBob: Drupal contains many undefined variables and array indices, which makes PHP throw a lot of warnings when the reporting level is set to E_ALL. Things run fine with these warnings, but as a matter of code style if nothing else we should probably strive to avoid them. The attached fixes most of the more egregious offenders (about 95% of the warnings when I load /node on my test site).
parent 3701c02e
...@@ -204,7 +204,9 @@ function arg($index) { ...@@ -204,7 +204,9 @@ function arg($index) {
$arguments = explode('/', $_GET['q']); $arguments = explode('/', $_GET['q']);
} }
return $arguments[$index]; if (array_key_exists($index, $arguments)) {
return $arguments[$index];
}
} }
function check_query($text) { function check_query($text) {
......
...@@ -234,7 +234,7 @@ function drupal_not_found() { ...@@ -234,7 +234,7 @@ function drupal_not_found() {
watchdog('httpd', t('404 error: "%page" not found', array('%page' => check_query($_GET["q"])))); watchdog('httpd', t('404 error: "%page" not found', array('%page' => check_query($_GET["q"]))));
$path = drupal_get_normal_path(variable_get('site_404', '')); $path = drupal_get_normal_path(variable_get('site_404', ''));
$status = MENU_FALLTHROUGH; $status = MENU_NOT_FOUND;
if ($path) { if ($path) {
menu_set_active_item($path); menu_set_active_item($path);
$status = menu_execute_active_handler(); $status = menu_execute_active_handler();
...@@ -252,7 +252,7 @@ function drupal_access_denied() { ...@@ -252,7 +252,7 @@ function drupal_access_denied() {
header('HTTP/1.0 403 Forbidden'); header('HTTP/1.0 403 Forbidden');
$path = drupal_get_normal_path(variable_get('site_403', '')); $path = drupal_get_normal_path(variable_get('site_403', ''));
$status = MENU_FALLTHROUGH; $status = MENU_NOT_FOUND;
if ($path) { if ($path) {
menu_set_active_item($path); menu_set_active_item($path);
$status = menu_execute_active_handler(); $status = menu_execute_active_handler();
...@@ -866,7 +866,8 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL ...@@ -866,7 +866,8 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL
$max = strlen($format); $max = strlen($format);
$date = ''; $date = '';
for ($i = 0; $i <= $max; $c = $format{$i++}) { for ($i = 0; $i < $max; $i++) {
$c = $format{$i};
if (strpos('AaDFlM', $c)) { if (strpos('AaDFlM', $c)) {
$date .= t(gmdate($c, $timestamp)); $date .= t(gmdate($c, $timestamp));
} }
...@@ -963,14 +964,16 @@ function form_set_error($name, $message) { ...@@ -963,14 +964,16 @@ function form_set_error($name, $message) {
* Return true when errors have been set. * Return true when errors have been set.
*/ */
function form_has_errors() { function form_has_errors() {
return isset($GLOBALS['form']); return array_key_exists('form', $GLOBALS);
} }
/** /**
* Return the error message filed against the form with the specified name. * Return the error message filed against the form with the specified name.
*/ */
function _form_get_error($name) { function _form_get_error($name) {
return $GLOBALS['form'][$name]; if (array_key_exists('form', $GLOBALS)) {
return $GLOBALS['form'][$name];
}
} }
function _form_get_class($name, $required, $error) { function _form_get_class($name, $required, $error) {
......
...@@ -200,12 +200,15 @@ function menu_execute_active_handler() { ...@@ -200,12 +200,15 @@ function menu_execute_active_handler() {
// Determine the menu item containing the callback. // Determine the menu item containing the callback.
$path = $_GET['q']; $path = $_GET['q'];
while ($path && (!$menu['path index'][$path] || !$menu['items'][$menu['path index'][$path]]['callback'])) { while ($path && (!array_key_exists($path, $menu['path index']) || empty($menu['items'][$menu['path index'][$path]]['callback']))) {
$path = substr($path, 0, strrpos($path, '/')); $path = substr($path, 0, strrpos($path, '/'));
} }
if (!array_key_exists($path, $menu['path index'])) {
return MENU_NOT_FOUND;
}
$mid = $menu['path index'][$path]; $mid = $menu['path index'][$path];
if (!is_string($menu['items'][$mid]['callback'])) { if (empty($menu['items'][$mid]['callback'])) {
return MENU_NOT_FOUND; return MENU_NOT_FOUND;
} }
...@@ -214,7 +217,7 @@ function menu_execute_active_handler() { ...@@ -214,7 +217,7 @@ function menu_execute_active_handler() {
} }
// We found one, and are allowed to execute it. // We found one, and are allowed to execute it.
$arguments = $menu['items'][$mid]['callback arguments'] ? $menu['items'][$mid]['callback arguments'] : array(); $arguments = $menu['items'][$mid]['callback arguments'];
$arg = substr($_GET['q'], strlen($menu['items'][$mid]['path']) + 1); $arg = substr($_GET['q'], strlen($menu['items'][$mid]['path']) + 1);
if (strlen($arg)) { if (strlen($arg)) {
$arguments = array_merge($arguments, explode('/', $arg)); $arguments = array_merge($arguments, explode('/', $arg));
...@@ -245,10 +248,10 @@ function menu_set_active_item($path = NULL) { ...@@ -245,10 +248,10 @@ function menu_set_active_item($path = NULL) {
$_GET['q'] = $path; $_GET['q'] = $path;
} }
while ($path && !$menu['path index'][$path]) { while ($path && !array_key_exists($path, $menu['path index'])) {
$path = substr($path, 0, strrpos($path, '/')); $path = substr($path, 0, strrpos($path, '/'));
} }
$stored_mid = $menu['path index'][$path]; $stored_mid = array_key_exists($path, $menu['path index']) ? $menu['path index'][$path] : 0;
} }
return $stored_mid; return $stored_mid;
...@@ -483,9 +486,12 @@ function _menu_get_trail($path) { ...@@ -483,9 +486,12 @@ function _menu_get_trail($path) {
$trail = array(); $trail = array();
// Find the ID of the given path. // Find the ID of the given path.
while ($path && !$menu['path index'][$path]) { while ($path && !array_key_exists($path, $menu['path index'])) {
$path = substr($path, 0, strrpos($path, '/')); $path = substr($path, 0, strrpos($path, '/'));
} }
if (!array_key_exists($path, $menu['path index'])) {
return array();
}
$mid = $menu['path index'][$path]; $mid = $menu['path index'][$path];
// Follow the parents up the chain to get the trail. // Follow the parents up the chain to get the trail.
...@@ -522,8 +528,8 @@ function _menu_build() { ...@@ -522,8 +528,8 @@ function _menu_build() {
$_menu['path index'] = array(); $_menu['path index'] = array();
// Set up items array, including default "Navigation" menu. // Set up items array, including default "Navigation" menu.
$_menu['items'] = array( $_menu['items'] = array(
0 => array('type' => MENU_IS_ROOT), 0 => array('path' => '', 'title' => '', 'type' => MENU_IS_ROOT),
1 => array('pid' => 0, 'title' => t('Navigation'), 'weight' => -50, 'access' => TRUE, 'type' => MENU_IS_ROOT | MENU_VISIBLE_IN_TREE) 1 => array('pid' => 0, 'path' => '', 'title' => t('Navigation'), 'weight' => -50, 'access' => TRUE, 'type' => MENU_IS_ROOT | MENU_VISIBLE_IN_TREE)
); );
// Build a sequential list of all menu items. // Build a sequential list of all menu items.
...@@ -533,11 +539,20 @@ function _menu_build() { ...@@ -533,11 +539,20 @@ function _menu_build() {
$temp_mid = -1; $temp_mid = -1;
foreach ($menu_item_list as $item) { foreach ($menu_item_list as $item) {
if (!isset($item['type'])) { if (!array_key_exists('path', $item)) {
$item['path'] = '';
}
if (!array_key_exists('type', $item)) {
$item['type'] = MENU_NORMAL_ITEM; $item['type'] = MENU_NORMAL_ITEM;
} }
if (!array_key_exists('weight', $item)) {
$item['weight'] = 0;
}
if (!array_key_exists('callback arguments', $item)) {
$item['callback arguments'] = array();
}
$mid = $temp_mid; $mid = $temp_mid;
if (isset($_menu['path index'][$item['path']])) { if (array_key_exists($item['path'], $_menu['path index'])) {
// Newer menu items overwrite older ones. // Newer menu items overwrite older ones.
unset($_menu['items'][$_menu['path index'][$item['path']]]); unset($_menu['items'][$_menu['path index'][$item['path']]]);
} }
...@@ -552,7 +567,8 @@ function _menu_build() { ...@@ -552,7 +567,8 @@ function _menu_build() {
$result = db_query('SELECT * FROM {menu}'); $result = db_query('SELECT * FROM {menu}');
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
// Don't display non-custom menu items if no module declared them. // Don't display non-custom menu items if no module declared them.
if ($old_mid = $_menu['path index'][$item->path]) { if (array_key_exists($item->path, $_menu['path index'])) {
$old_mid = $_menu['path index'][$item->path];
$_menu['items'][$item->mid] = $_menu['items'][$old_mid]; $_menu['items'][$item->mid] = $_menu['items'][$old_mid];
unset($_menu['items'][$old_mid]); unset($_menu['items'][$old_mid]);
$_menu['path index'][$item->path] = $item->mid; $_menu['path index'][$item->path] = $item->mid;
...@@ -566,7 +582,7 @@ function _menu_build() { ...@@ -566,7 +582,7 @@ function _menu_build() {
} }
// Next, add any custom items added by the administrator. // Next, add any custom items added by the administrator.
else if ($item->type & MENU_CREATED_BY_ADMIN) { else if ($item->type & MENU_CREATED_BY_ADMIN) {
$_menu['items'][$item->mid] = array('pid' => $item->pid, 'path' => $item->path, 'title' => $item->title, 'access' => TRUE, 'weight' => $item->weight, 'type' => $item->type); $_menu['items'][$item->mid] = array('pid' => $item->pid, 'path' => $item->path, 'title' => $item->title, 'access' => TRUE, 'weight' => $item->weight, 'type' => $item->type, 'callback' => '', 'callback arguments' => array());
$_menu['path index'][$item->path] = $item->mid; $_menu['path index'][$item->path] = $item->mid;
} }
} }
...@@ -580,7 +596,7 @@ function _menu_build() { ...@@ -580,7 +596,7 @@ function _menu_build() {
do { do {
$parent = substr($parent, 0, strrpos($parent, '/')); $parent = substr($parent, 0, strrpos($parent, '/'));
} }
while ($parent && !$_menu['path index'][$parent]); while ($parent && !array_key_exists($parent, $_menu['path index']));
$pid = $parent ? $_menu['path index'][$parent] : 1; $pid = $parent ? $_menu['path index'][$parent] : 1;
$_menu['items'][$mid]['pid'] = $pid; $_menu['items'][$mid]['pid'] = $pid;
...@@ -615,15 +631,18 @@ function _menu_build() { ...@@ -615,15 +631,18 @@ function _menu_build() {
function _menu_item_is_accessible($mid) { function _menu_item_is_accessible($mid) {
$menu = menu_get_menu(); $menu = menu_get_menu();
if (isset($menu['items'][$mid]['access'])) { if (array_key_exists('access', $menu['items'][$mid])) {
return $menu['items'][$mid]['access']; return $menu['items'][$mid]['access'];
} }
// Follow the path up to find the actual callback. // Follow the path up to find the actual callback.
$path = $menu['items'][$mid]['path']; $path = $menu['items'][$mid]['path'];
while ($path && (!$menu['path index'][$path] || !$menu['items'][$menu['path index'][$path]]['callback'])) { while ($path && (!array_key_exists($path, $menu['path index']) || !array_key_exists('callback', $menu['items'][$menu['path index'][$path]]))) {
$path = substr($path, 0, strrpos($path, '/')); $path = substr($path, 0, strrpos($path, '/'));
} }
if (empty($path)) {
return FALSE;
}
$callback_mid = $menu['path index'][$path]; $callback_mid = $menu['path index'][$path];
return $menu['items'][$callback_mid]['access']; return $menu['items'][$callback_mid]['access'];
} }
...@@ -641,7 +660,7 @@ function _menu_build_visible_tree($pid = 0) { ...@@ -641,7 +660,7 @@ function _menu_build_visible_tree($pid = 0) {
$parent = $_menu['items'][$pid]; $parent = $_menu['items'][$pid];
$children = array(); $children = array();
if ($parent['children']) { if (array_key_exists('children', $parent)) {
usort($parent['children'], '_menu_sort'); usort($parent['children'], '_menu_sort');
foreach ($parent['children'] as $mid) { foreach ($parent['children'] as $mid) {
$children = array_merge($children, _menu_build_visible_tree($mid)); $children = array_merge($children, _menu_build_visible_tree($mid));
...@@ -679,31 +698,33 @@ function _menu_build_local_tasks() { ...@@ -679,31 +698,33 @@ function _menu_build_local_tasks() {
$tasks[0] = array('children' => array()); $tasks[0] = array('children' => array());
$mid = menu_get_active_nontask_item(); $mid = menu_get_active_nontask_item();
$tasks[$mid] = array('title' => $_menu['items'][$mid]['title'], 'path' => $_menu['items'][$mid]['path'], 'children' => array()); if ($mid) {
$tasks[0]['children'][] = $mid; $tasks[$mid] = array('title' => $_menu['items'][$mid]['title'], 'path' => $_menu['items'][$mid]['path'], 'children' => array());
$tasks[0]['children'][] = $mid;
// Find top-level tasks
if ($children = $_menu['items'][$mid]['children']) {
foreach ($children as $cid) {
if (($_menu['items'][$cid]['type'] & MENU_IS_LOCAL_TASK) && _menu_item_is_accessible($cid)) {
$tasks[$cid] = array('title' => $_menu['items'][$cid]['title'], 'path' => $_menu['items'][$cid]['path'], 'children' => array());
$tasks[0]['children'][] = $cid;
}
}
}
usort($tasks[0]['children'], '_menu_sort');
// Find subtasks // Find top-level tasks
foreach ($tasks[0]['children'] as $mid) {
if ($children = $_menu['items'][$mid]['children']) { if ($children = $_menu['items'][$mid]['children']) {
foreach ($children as $cid) { foreach ($children as $cid) {
if (($_menu['items'][$cid]['type'] & MENU_IS_LOCAL_SUBTASK) && _menu_item_is_accessible($cid)) { if (($_menu['items'][$cid]['type'] & MENU_IS_LOCAL_TASK) && _menu_item_is_accessible($cid)) {
$tasks[$cid] = array('title' => $_menu['items'][$cid]['title'], 'path' => $_menu['items'][$cid]['path'], 'children' => array()); $tasks[$cid] = array('title' => $_menu['items'][$cid]['title'], 'path' => $_menu['items'][$cid]['path'], 'children' => array());
$tasks[$mid]['children'][] = $cid; $tasks[0]['children'][] = $cid;
}
}
}
usort($tasks[0]['children'], '_menu_sort');
// Find subtasks
foreach ($tasks[0]['children'] as $mid) {
if ($children = $_menu['items'][$mid]['children']) {
foreach ($children as $cid) {
if (($_menu['items'][$cid]['type'] & MENU_IS_LOCAL_SUBTASK) && _menu_item_is_accessible($cid)) {
$tasks[$cid] = array('title' => $_menu['items'][$cid]['title'], 'path' => $_menu['items'][$cid]['path'], 'children' => array());
$tasks[$mid]['children'][] = $cid;
}
} }
} }
usort($tasks[$mid]['children'], '_menu_sort');
} }
usort($tasks[$mid]['children'], '_menu_sort');
} }
if (count($tasks) > 2) { if (count($tasks) > 2) {
......
...@@ -70,6 +70,8 @@ function pager_query($query, $limit = 10, $element = 0, $count_query = "") { ...@@ -70,6 +70,8 @@ function pager_query($query, $limit = 10, $element = 0, $count_query = "") {
*/ */
function theme_pager($tags = "", $limit = 10, $element = 0, $attributes = array()) { function theme_pager($tags = "", $limit = 10, $element = 0, $attributes = array()) {
global $pager_total; global $pager_total;
$output = '';
if ($pager_total[$element] > $limit) { if ($pager_total[$element] > $limit) {
$output .= "<div id=\"pager\" class=\"container-inline\">"; $output .= "<div id=\"pager\" class=\"container-inline\">";
$output .= "<div>". pager_first(($tags[0] ? $tags[0] : t("first page")), $limit, $element, $attributes) ."</div>"; $output .= "<div>". pager_first(($tags[0] ? $tags[0] : t("first page")), $limit, $element, $attributes) ."</div>";
...@@ -282,8 +284,8 @@ function pager_list($limit, $element = 0, $quantity = 5, $text = "", $attributes ...@@ -282,8 +284,8 @@ function pager_list($limit, $element = 0, $quantity = 5, $text = "", $attributes
/* @} End of member group pager pieces */ /* @} End of member group pager pieces */
function pager_link($from_new, $element, $attributes = array()) { function pager_link($from_new, $element, $attributes = array()) {
$q = $_GET["q"]; $q = $_GET['q'];
$from = $_GET["from"]; $from = array_key_exists('from', $_GET) ? $_GET['from'] : '';
foreach($attributes as $key => $value) { foreach($attributes as $key => $value) {
$query[] = "$key=$value"; $query[] = "$key=$value";
......
...@@ -46,7 +46,7 @@ function init_theme() { ...@@ -46,7 +46,7 @@ function init_theme() {
** list of enabled themes. ** list of enabled themes.
*/ */
$theme = $themes[$user->theme] ? $user->theme : variable_get("theme_default", 0); $theme = $user->theme && $themes[$user->theme] ? $user->theme : variable_get("theme_default", 0);
include_once($themes[$theme]->filename); include_once($themes[$theme]->filename);
...@@ -519,6 +519,8 @@ function theme_blocks($region) { ...@@ -519,6 +519,8 @@ function theme_blocks($region) {
/* @} */ /* @} */
function _theme_table_cell($cell, $header = 0) { function _theme_table_cell($cell, $header = 0) {
$attributes = '';
if (is_array($cell)) { if (is_array($cell)) {
$data = $cell['data']; $data = $cell['data'];
foreach ($cell as $key => $value) { foreach ($cell as $key => $value) {
......
...@@ -47,10 +47,8 @@ function help_glossary() { ...@@ -47,10 +47,8 @@ function help_glossary() {
function help_help($section) { function help_help($section) {
switch ($section) { switch ($section) {
case 'admin/modules#description': case 'admin/modules#description':
$output = t('Manages displaying online help.'); return t('Manages displaying online help.');
break;
} }
return $output;
} }
/** /**
......
...@@ -47,10 +47,8 @@ function help_glossary() { ...@@ -47,10 +47,8 @@ function help_glossary() {
function help_help($section) { function help_help($section) {
switch ($section) { switch ($section) {
case 'admin/modules#description': case 'admin/modules#description':
$output = t('Manages displaying online help.'); return t('Manages displaying online help.');
break;
} }
return $output;
} }
/** /**
......
...@@ -620,7 +620,7 @@ function node_link($type, $node = 0, $main = 0) { ...@@ -620,7 +620,7 @@ function node_link($type, $node = 0, $main = 0) {
$links = array(); $links = array();
if ($type == 'node') { if ($type == 'node') {
if ($node->links) { if (array_key_exists('links', $node)) {
$links = $node->links; $links = $node->links;
} }
......
...@@ -620,7 +620,7 @@ function node_link($type, $node = 0, $main = 0) { ...@@ -620,7 +620,7 @@ function node_link($type, $node = 0, $main = 0) {
$links = array(); $links = array();
if ($type == 'node') { if ($type == 'node') {
if ($node->links) { if (array_key_exists('links', $node)) {
$links = $node->links; $links = $node->links;
} }
......
...@@ -38,7 +38,7 @@ function taxonomy_perm() { ...@@ -38,7 +38,7 @@ function taxonomy_perm() {
function taxonomy_link($type, $node = NULL) { function taxonomy_link($type, $node = NULL) {
if ($type == 'taxonomy terms' && $node != NULL) { if ($type == 'taxonomy terms' && $node != NULL) {
$links = array(); $links = array();
if ($node->taxonomy) { if (array_key_exists('taxonomy', $node)) {
foreach ($node->taxonomy as $tid) { foreach ($node->taxonomy as $tid) {
$term = taxonomy_get_term($tid); $term = taxonomy_get_term($tid);
$links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array ('title' => $term->description) : array()); $links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array ('title' => $term->description) : array());
......
...@@ -38,7 +38,7 @@ function taxonomy_perm() { ...@@ -38,7 +38,7 @@ function taxonomy_perm() {
function taxonomy_link($type, $node = NULL) { function taxonomy_link($type, $node = NULL) {
if ($type == 'taxonomy terms' && $node != NULL) { if ($type == 'taxonomy terms' && $node != NULL) {
$links = array(); $links = array();
if ($node->taxonomy) { if (array_key_exists('taxonomy', $node)) {
foreach ($node->taxonomy as $tid) { foreach ($node->taxonomy as $tid) {
$term = taxonomy_get_term($tid); $term = taxonomy_get_term($tid);
$links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array ('title' => $term->description) : array()); $links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array ('title' => $term->description) : array());
......
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