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 @@ ...@@ -10,15 +10,11 @@
* - _sess_close() * - _sess_close()
* - _sess_read() * - _sess_read()
* - _sess_write() * - _sess_write()
* - _sess_destroy_sid()
* - _sess_gc()
* are assigned by session_set_save_handler() in bootstrap.inc and are called * are assigned by session_set_save_handler() in bootstrap.inc and are called
* automatically by PHP. These functions should not be called directly. Session * automatically by PHP. These functions should not be called directly. Session
* data should instead be accessed via the $_SESSION superglobal. * 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() { ...@@ -64,7 +60,7 @@ function _sess_close() {
* instead be accessed via the $_SESSION superglobal. * instead be accessed via the $_SESSION superglobal.
* *
* @param $key * @param $key
* Session ID * Session ID.
* @return * @return
* Either an array of the session data, or an empty string, if no data * Either an array of the session data, or an empty string, if no data
* was found or the user is anonymous. * was found or the user is anonymous.
...@@ -89,12 +85,12 @@ function _sess_read($key) { ...@@ -89,12 +85,12 @@ function _sess_read($key) {
// client's session in the database. // 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)); $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) { 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); $user = drupal_unpack($user);
// Add roles element to $user // Add roles element to $user.
$user->roles = array(); $user->roles = array();
$user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; $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); $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) { ...@@ -122,7 +118,7 @@ function _sess_read($key) {
* instead be accessed via the $_SESSION superglobal. * instead be accessed via the $_SESSION superglobal.
* *
* @param $key * @param $key
* Session ID * Session ID.
* @param $value * @param $value
* Serialized array of the session data. * Serialized array of the session data.
* @return * @return
...@@ -177,16 +173,19 @@ function drupal_session_regenerate() { ...@@ -177,16 +173,19 @@ function drupal_session_regenerate() {
} }
/** /**
* Counts how many users have sessions. Can count either anonymous sessions, * Counts how many users are active on the site.
* authenticated sessions, or both.
* *
* @param int $timestamp * Counts how many users have sessions which have been active since the
* A Unix timestamp representing a point of time in the past. * specified time. Can count either anonymous sessions or
* The default is 0, which counts all existing sessions. * 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 * @param boolean $anonymous
* TRUE counts only anonymous users. * TRUE counts only anonymous users.
* FALSE counts only authenticated users. * FALSE counts only authenticated users.
* @return int * @return int
* The number of users with sessions. * The number of users with sessions.
*/ */
function drupal_session_count($timestamp = 0, $anonymous = TRUE) { function drupal_session_count($timestamp = 0, $anonymous = TRUE) {
...@@ -199,18 +198,18 @@ function drupal_session_count($timestamp = 0, $anonymous = TRUE) { ...@@ -199,18 +198,18 @@ function drupal_session_count($timestamp = 0, $anonymous = TRUE) {
* *
* Cleanup a specific session. * Cleanup a specific session.
* *
* @param string $sid * @param string $sid
* the session id * Session ID.
*/ */
function _sess_destroy_sid($sid) { function _sess_destroy_sid($sid) {
db_query("DELETE FROM {sessions} WHERE sid = '%s'", $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 * @param string $uid
* the user id * User ID.
*/ */
function drupal_session_destroy_uid($uid) { function drupal_session_destroy_uid($uid) {
db_query('DELETE FROM {sessions} WHERE uid = %d', $uid); db_query('DELETE FROM {sessions} WHERE uid = %d', $uid);
...@@ -220,6 +219,10 @@ function drupal_session_destroy_uid($uid) { ...@@ -220,6 +219,10 @@ function drupal_session_destroy_uid($uid) {
* Session handler assigned by session_set_save_handler(). * Session handler assigned by session_set_save_handler().
* *
* Cleanup stalled sessions. * 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) { function _sess_gc($lifetime) {
// Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough // Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough
...@@ -238,7 +241,7 @@ function _sess_gc($lifetime) { ...@@ -238,7 +241,7 @@ function _sess_gc($lifetime) {
* This function allows the caller to temporarily disable writing of * This function allows the caller to temporarily disable writing of
* session data, should the request end while performing potentially * session data, should the request end while performing potentially
* dangerous operations, such as manipulating the global $user object. * 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 * @param $status
* Disables writing of session data when FALSE, (re-)enables * Disables writing of session data when FALSE, (re-)enables
......
...@@ -295,7 +295,7 @@ function book_get_books() { ...@@ -295,7 +295,7 @@ function book_get_books() {
*/ */
function book_form_alter(&$form, $form_state, $form_id) { 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. // Add elements to the node form.
$node = $form['#node']; $node = $form['#node'];
......
...@@ -532,24 +532,22 @@ function comment_form_alter(&$form, $form_state, $form_id) { ...@@ -532,24 +532,22 @@ function comment_form_alter(&$form, $form_state, $form_id) {
'#options' => array(t('Display on separate page'), t('Display below post or comments')), '#options' => array(t('Display on separate page'), t('Display below post or comments')),
); );
} }
elseif (isset($form['type']) && isset($form['#node'])) { elseif (!empty($form['#node_edit_form'])) {
if ($form['type']['#value'] . '_node_form' == $form_id) { $node = $form['#node'];
$node = $form['#node']; $form['comment_settings'] = array(
$form['comment_settings'] = array( '#type' => 'fieldset',
'#type' => 'fieldset', '#access' => user_access('administer comments'),
'#access' => user_access('administer comments'), '#title' => t('Comment settings'),
'#title' => t('Comment settings'), '#collapsible' => TRUE,
'#collapsible' => TRUE, '#collapsed' => TRUE,
'#collapsed' => TRUE, '#weight' => 30,
'#weight' => 30, );
); $form['comment_settings']['comment'] = array(
$form['comment_settings']['comment'] = array( '#type' => 'radios',
'#type' => 'radios', '#parents' => array('comment'),
'#parents' => array('comment'), '#default_value' => $node->comment,
'#default_value' => $node->comment, '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
'#options' => array(t('Disabled'), t('Read only'), t('Read/Write')), );
);
}
} }
} }
......
...@@ -350,7 +350,7 @@ function _menu_parent_depth_limit($item) { ...@@ -350,7 +350,7 @@ function _menu_parent_depth_limit($item) {
* Implementation of hook_form_alter(). Adds menu item fields to the node form. * Implementation of hook_form_alter(). Adds menu item fields to the node form.
*/ */
function menu_form_alter(&$form, $form_state, $form_id) { 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. // Note - doing this to make sure the delete checkbox stays in the form.
$form['#cache'] = TRUE; $form['#cache'] = TRUE;
......
...@@ -117,8 +117,9 @@ function node_form(&$form_state, $node) { ...@@ -117,8 +117,9 @@ function node_form(&$form_state, $node) {
$node->build_mode = NODE_BUILD_PREVIEW; $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['#id'] = 'node-form';
$form['#node_edit_form'] = TRUE;
// Basic node information. // Basic node information.
// These elements are just values so they are not even sent to the client. // These elements are just values so they are not even sent to the client.
......
...@@ -172,7 +172,7 @@ function path_nodeapi(&$node, $op, $arg) { ...@@ -172,7 +172,7 @@ function path_nodeapi(&$node, $op, $arg) {
* Implementation of hook_form_alter(). * Implementation of hook_form_alter().
*/ */
function path_form_alter(&$form, $form_state, $form_id) { 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; $path = isset($form['#node']->path) ? $form['#node']->path : NULL;
$form['path'] = array( $form['path'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
......
...@@ -503,7 +503,7 @@ function taxonomy_get_vocabularies($type = NULL) { ...@@ -503,7 +503,7 @@ function taxonomy_get_vocabularies($type = NULL) {
* and provide scalable alternatives. * and provide scalable alternatives.
*/ */
function taxonomy_form_alter(&$form, $form_state, $form_id) { 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']; $node = $form['#node'];
if (!isset($node->taxonomy)) { if (!isset($node->taxonomy)) {
......
...@@ -217,9 +217,9 @@ function upload_form_alter(&$form, $form_state, $form_id) { ...@@ -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']; $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 // Attachments fieldset
$form['attachments'] = array( $form['attachments'] = array(
'#type' => 'fieldset', '#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