$value) { $cond[] = 'n.'. db_escape_table($key) ." = '%s'"; $arguments[] = $value; } $cond = implode(' AND ', $cond); } else { return FALSE; } // Retrieve a field list based on the site's schema. $fields = drupal_schema_fields_sql('node', 'n'); $fields = array_merge($fields, drupal_schema_fields_sql('node_revisions', 'r')); $fields = array_merge($fields, array('u.name', 'u.picture', 'u.data')); // Remove fields not needed in the query: n.vid and r.nid are redundant, // n.title is unnecessary because the node title comes from the // node_revisions table. We'll keep r.vid, r.title, and n.nid. $fields = array_diff($fields, array('n.vid', 'n.title', 'r.nid')); $fields = implode(', ', $fields); // Rename timestamp field for clarity. $fields = str_replace('r.timestamp', 'r.timestamp AS revision_timestamp', $fields); // Change name of revision uid so it doesn't conflict with n.uid. $fields = str_replace('r.uid', 'r.uid AS revision_uid', $fields); // Retrieve the node. // No db_rewrite_sql is applied so as to get complete indexing for search. if ($revision) { array_unshift($arguments, $revision); $node = db_fetch_object(db_query('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments)); } else { $node = db_fetch_object(db_query('SELECT '. $fields .' FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments)); } if ($node && $node->nid) { if ($cachable) { $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node; } } return $node; } /** * Function to decide whether a profile page can be replaced by content profile * For now just checking if there's only one node. * TODO: Provide UI for advance use cases, i.e. selection of a specific * node/content type for replacement. * * @param int $uid * user id * @return mixed * FALSE if no replacement is found or node ID of the content profile */ function content_profile_replace_is_replaceable($uid) { $nid = FALSE; foreach (content_profile_get_types('names') as $type => $type_name) { // Using custom module instead of content_profile_load($type, $uid); // I am not caching anything as content_profile_load() but I don't think is // necessary, otherwise I have also do a custom content_profile_load(). $params = array('type' => $type, 'uid' => $uid); $nodes[] = content_profile_replace_node_load($lang ? $params + array('language' => $lang) : $params, NULL, $reset); } if (count($nodes) == 1 && $nodes[0]->nid) { $nid = $nodes[0]->nid; } return $nid; } /** * Replacement menu callback for user/%user_uid_optional that shows * the content profile node instead of the drupal user profile page. * * It defaults to the drupal user page if no profile exists for the user */ function content_profile_replace_user_view($account) { // Only display the node if only one node was found as a content profile $nid = content_profile_replace_is_replaceable($account->uid); $node = node_load($nid); // Display the node if exists and if the user have access to it // This access validation goes on top of the user/%user_uid_optional access. if (node_access('view', $node)) { $node = node_load($nid); $content = node_page_view($node); } else { $content = user_view($account); } return $content; }