Commit 9f3d9f11 authored by Dries's avatar Dries

- Patch #161301 by Eaton, Sun, moshe and webchick: make checking for node edit...

- Patch #161301 by Eaton, Sun, moshe and webchick: make checking for node edit forms easier. DX improvement.
parent 0d84b918
......@@ -10,15 +10,11 @@
* - _sess_close()
* - _sess_read()
* - _sess_write()
* - _sess_destroy_sid()
* - _sess_gc()
* are assigned by session_set_save_handler() in bootstrap.inc and are called
* automatically by PHP. These functions should not be called directly. Session
* data should instead be accessed via the $_SESSION superglobal.
*
* The user-level session storage handlers:
* - sess_destroy_sid()
* - sess_gc()
* are assigned by session_set_save_handler() in bootstrap.inc and are called
* automatically by PHP, but they may safely be called directly.
*/
/**
......@@ -64,7 +60,7 @@ function _sess_close() {
* instead be accessed via the $_SESSION superglobal.
*
* @param $key
* Session ID
* Session ID.
* @return
* Either an array of the session data, or an empty string, if no data
* was found or the user is anonymous.
......@@ -89,12 +85,12 @@ function _sess_read($key) {
// client's session in the database.
$user = db_fetch_object(db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = '%s'", $key));
// We found the client's session record and they are an authenticated user
// We found the client's session record and they are an authenticated user.
if ($user && $user->uid > 0) {
// This is done to unserialize the data member of $user
// This is done to unserialize the data member of $user.
$user = drupal_unpack($user);
// Add roles element to $user
// Add roles element to $user.
$user->roles = array();
$user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
$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);
......@@ -122,7 +118,7 @@ function _sess_read($key) {
* instead be accessed via the $_SESSION superglobal.
*
* @param $key
* Session ID
* Session ID.
* @param $value
* Serialized array of the session data.
* @return
......@@ -177,12 +173,15 @@ function drupal_session_regenerate() {
}
/**
* Counts how many users have sessions. Can count either anonymous sessions,
* authenticated sessions, or both.
* Counts how many users are active on the site.
*
* @param int $timestamp
* A Unix timestamp representing a point of time in the past.
* The default is 0, which counts all existing sessions.
* Counts how many users have sessions which have been active since the
* specified time. Can count either anonymous sessions or
* authenticated sessions.
*
* @param int $timestamp.
* A Unix timestamp. Users who have been active since this time will be
* counted. The default is 0, which counts all existing sessions.
* @param boolean $anonymous
* TRUE counts only anonymous users.
* FALSE counts only authenticated users.
......@@ -200,17 +199,17 @@ function drupal_session_count($timestamp = 0, $anonymous = TRUE) {
* Cleanup a specific session.
*
* @param string $sid
* the session id
* Session ID.
*/
function _sess_destroy_sid($sid) {
db_query("DELETE FROM {sessions} WHERE sid = '%s'", $sid);
}
/**
* End a specific user's session
* End a specific user's session(s).
*
* @param string $uid
* the user id
* User ID.
*/
function drupal_session_destroy_uid($uid) {
db_query('DELETE FROM {sessions} WHERE uid = %d', $uid);
......@@ -220,6 +219,10 @@ function drupal_session_destroy_uid($uid) {
* Session handler assigned by session_set_save_handler().
*
* Cleanup stalled sessions.
*
* @param int $lifetime
* The value of session.gc_maxlifetime, passed by PHP.
* Sessions not updated for more than $lifetime seconds will be removed.
*/
function _sess_gc($lifetime) {
// Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough
......@@ -238,7 +241,7 @@ function _sess_gc($lifetime) {
* This function allows the caller to temporarily disable writing of
* session data, should the request end while performing potentially
* dangerous operations, such as manipulating the global $user object.
* See http://drupal.org/node/218104 for usage
* See http://drupal.org/node/218104 for usage.
*
* @param $status
* Disables writing of session data when FALSE, (re-)enables
......
......@@ -295,7 +295,7 @@ function book_get_books() {
*/
function book_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
if (!empty($form['#node_edit_form'])) {
// Add elements to the node form.
$node = $form['#node'];
......
......@@ -532,8 +532,7 @@ function comment_form_alter(&$form, $form_state, $form_id) {
'#options' => array(t('Display on separate page'), t('Display below post or comments')),
);
}
elseif (isset($form['type']) && isset($form['#node'])) {
if ($form['type']['#value'] . '_node_form' == $form_id) {
elseif (!empty($form['#node_edit_form'])) {
$node = $form['#node'];
$form['comment_settings'] = array(
'#type' => 'fieldset',
......@@ -550,7 +549,6 @@ function comment_form_alter(&$form, $form_state, $form_id) {
'#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
);
}
}
}
/**
......
......@@ -350,7 +350,7 @@ function _menu_parent_depth_limit($item) {
* Implementation of hook_form_alter(). Adds menu item fields to the node form.
*/
function menu_form_alter(&$form, $form_state, $form_id) {
if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {
if (!empty($form['#node_edit_form'])) {
// Note - doing this to make sure the delete checkbox stays in the form.
$form['#cache'] = TRUE;
......
......@@ -117,8 +117,9 @@ function node_form(&$form_state, $node) {
$node->build_mode = NODE_BUILD_PREVIEW;
}
// Set the id of the top-level form tag
// Set the id and identify this as a node edit form.
$form['#id'] = 'node-form';
$form['#node_edit_form'] = TRUE;
// Basic node information.
// These elements are just values so they are not even sent to the client.
......
......@@ -172,7 +172,7 @@ function path_nodeapi(&$node, $op, $arg) {
* Implementation of hook_form_alter().
*/
function path_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
if (!empty($form['#node_edit_form'])) {
$path = isset($form['#node']->path) ? $form['#node']->path : NULL;
$form['path'] = array(
'#type' => 'fieldset',
......
......@@ -503,7 +503,7 @@ function taxonomy_get_vocabularies($type = NULL) {
* and provide scalable alternatives.
*/
function taxonomy_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && (!variable_get('taxonomy_override_selector', FALSE)) && $form['type']['#value'] . '_node_form' == $form_id) {
if (!variable_get('taxonomy_override_selector', FALSE) && !empty($form['#node_edit_form'])) {
$node = $form['#node'];
if (!isset($node->taxonomy)) {
......
......@@ -217,9 +217,9 @@ function upload_form_alter(&$form, $form_state, $form_id) {
);
}
if (isset($form['type']) && isset($form['#node'])) {
if (!empty($form['#node_edit_form'])) {
$node = $form['#node'];
if ($form['type']['#value'] . '_node_form' == $form_id && variable_get("upload_$node->type", TRUE)) {
if (variable_get("upload_$node->type", TRUE)) {
// Attachments fieldset
$form['attachments'] = array(
'#type' => 'fieldset',
......
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