@@ -364,32 +364,32 @@ |
||
364 | 364 | $bits = preg_split('/[.@]/', $elattr, 2); |
365 | 365 | $c = count($bits); |
366 | 366 | switch ($c) { |
367 | - case 2: |
|
368 | - if ($bits[0] !== '*') { |
|
369 | - $element = htmlspecialchars($bits[0]); |
|
370 | - $attribute = htmlspecialchars($bits[1]); |
|
371 | - if (!isset($this->info[$element])) { |
|
372 | - trigger_error( |
|
373 | - "Cannot allow attribute '$attribute' if element " . |
|
374 | - "'$element' is not allowed/supported $support" |
|
375 | - ); |
|
376 | - } else { |
|
377 | - trigger_error( |
|
378 | - "Attribute '$attribute' in element '$element' not supported $support", |
|
379 | - E_USER_WARNING |
|
380 | - ); |
|
381 | - } |
|
382 | - break; |
|
367 | + case 2: |
|
368 | + if ($bits[0] !== '*') { |
|
369 | + $element = htmlspecialchars($bits[0]); |
|
370 | + $attribute = htmlspecialchars($bits[1]); |
|
371 | + if (!isset($this->info[$element])) { |
|
372 | + trigger_error( |
|
373 | + "Cannot allow attribute '$attribute' if element " . |
|
374 | + "'$element' is not allowed/supported $support" |
|
375 | + ); |
|
376 | + } else { |
|
377 | + trigger_error( |
|
378 | + "Attribute '$attribute' in element '$element' not supported $support", |
|
379 | + E_USER_WARNING |
|
380 | + ); |
|
383 | 381 | } |
384 | - // otherwise fall through |
|
385 | - case 1: |
|
386 | - $attribute = htmlspecialchars($bits[0]); |
|
387 | - trigger_error( |
|
388 | - "Global attribute '$attribute' is not ". |
|
389 | - "supported in any elements $support", |
|
390 | - E_USER_WARNING |
|
391 | - ); |
|
392 | 382 | break; |
383 | + } |
|
384 | + // otherwise fall through |
|
385 | + case 1: |
|
386 | + $attribute = htmlspecialchars($bits[0]); |
|
387 | + trigger_error( |
|
388 | + "Global attribute '$attribute' is not ". |
|
389 | + "supported in any elements $support", |
|
390 | + E_USER_WARNING |
|
391 | + ); |
|
392 | + break; |
|
393 | 393 | } |
394 | 394 | } |
395 | 395 | } |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | function htmlpurifier_help($path, $arg) { |
24 | 24 | $output = NULL; |
25 | 25 | switch ($path) { |
26 | - case 'admin/modules#htmlpurifier': |
|
27 | - $output = t('Filter that removes malicious HTML and ensures standards compliant output.'); |
|
28 | - break; |
|
26 | + case 'admin/modules#htmlpurifier': |
|
27 | + $output = t('Filter that removes malicious HTML and ensures standards compliant output.'); |
|
28 | + break; |
|
29 | 29 | } |
30 | 30 | return $output; |
31 | 31 | } |
@@ -66,38 +66,38 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function htmlpurifier_filter($op, $delta = 0, $format = -1, $text = '') { |
68 | 68 | switch ($op) { |
69 | - case 'list': |
|
70 | - return array(0 => t('HTML Purifier'), 1 => t('HTML Purifier (advanced)')); |
|
71 | - |
|
72 | - case 'no cache': |
|
73 | - // Since HTML Purifier implements its own caching layer, having filter |
|
74 | - // cache it again is wasteful. Returns FALSE if double caching is permitted. |
|
75 | - return !variable_get("htmlpurifier_doublecache", FALSE); |
|
76 | - |
|
77 | - case 'description': |
|
78 | - $common = t( |
|
79 | - 'Removes malicious HTML code and ensures that the output '. |
|
80 | - 'is standards compliant. <strong>Warning:</strong> For performance '. |
|
81 | - 'reasons, please ensure that there are no highly dynamic filters before HTML Purifier. ' |
|
82 | - ); |
|
83 | - switch ($delta) { |
|
84 | - case 0: |
|
85 | - return $common; |
|
86 | - case 1: |
|
87 | - return $common . t('<em>This version has advanced configuration options, do not enable both at the same time.</em>'); |
|
88 | - } |
|
69 | + case 'list': |
|
70 | + return array(0 => t('HTML Purifier'), 1 => t('HTML Purifier (advanced)')); |
|
71 | + |
|
72 | + case 'no cache': |
|
73 | + // Since HTML Purifier implements its own caching layer, having filter |
|
74 | + // cache it again is wasteful. Returns FALSE if double caching is permitted. |
|
75 | + return !variable_get("htmlpurifier_doublecache", FALSE); |
|
76 | + |
|
77 | + case 'description': |
|
78 | + $common = t( |
|
79 | + 'Removes malicious HTML code and ensures that the output '. |
|
80 | + 'is standards compliant. <strong>Warning:</strong> For performance '. |
|
81 | + 'reasons, please ensure that there are no highly dynamic filters before HTML Purifier. ' |
|
82 | + ); |
|
83 | + switch ($delta) { |
|
84 | + case 0: |
|
85 | + return $common; |
|
86 | + case 1: |
|
87 | + return $common . t('<em>This version has advanced configuration options, do not enable both at the same time.</em>'); |
|
88 | + } |
|
89 | 89 | |
90 | - case 'prepare': |
|
91 | - return $text; |
|
90 | + case 'prepare': |
|
91 | + return $text; |
|
92 | 92 | |
93 | - case 'process': |
|
94 | - return _htmlpurifier_process($text, $format); |
|
93 | + case 'process': |
|
94 | + return _htmlpurifier_process($text, $format); |
|
95 | 95 | |
96 | - case 'settings': |
|
97 | - return _htmlpurifier_settings($delta, $format); |
|
96 | + case 'settings': |
|
97 | + return _htmlpurifier_settings($delta, $format); |
|
98 | 98 | |
99 | - default: |
|
100 | - return NULL; |
|
99 | + default: |
|
100 | + return NULL; |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
2 | +/** |
|
3 | 3 | * This template is used to print a single field in a view. It is not |
4 | 4 | * actually used in default Views, as this is registered as a theme |
5 | 5 | * function which has better performance. For single overrides, the |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
2 | +/** |
|
3 | 3 | * This template is used to print a single field in a view. It is not |
4 | 4 | * actually used in default Views, as this is registered as a theme |
5 | 5 | * function which has better performance. For single overrides, the |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
2 | +/** |
|
3 | 3 | * This template is used to print a single field in a view. It is not |
4 | 4 | * actually used in default Views, as this is registered as a theme |
5 | 5 | * function which has better performance. For single overrides, the |
@@ -59,44 +59,44 @@ |
||
59 | 59 | $is_own_profile = ($user->uid == $account->uid); |
60 | 60 | |
61 | 61 | if ($user->uid AND ($user->uid != $account->uid)) { |
62 | - if (module_exists('private_messages')) { |
|
63 | - // if (function_exists('privatemsg_get_link')) { |
|
64 | - $user_links[] = array( |
|
65 | - 'title' => bts('Send message'), |
|
66 | - 'href' => privatemsg_get_link(array($account)) |
|
67 | - ); |
|
68 | - } |
|
62 | +if (module_exists('private_messages')) { |
|
63 | +// if (function_exists('privatemsg_get_link')) { |
|
64 | + $user_links[] = array( |
|
65 | + 'title' => bts('Send message'), |
|
66 | + 'href' => privatemsg_get_link(array($account)) |
|
67 | + ); |
|
68 | +} |
|
69 | 69 | |
70 | - if (module_exists('friends')) { |
|
71 | - $flag = flag_get_flag('friend'); |
|
72 | - $friend_status = flag_friend_determine_friend_status($flag, $account->uid, $user->uid); |
|
73 | - switch ($friend_status) { |
|
74 | - case FLAG_FRIEND_BOTH: |
|
75 | - case FLAG_FRIEND_FLAGGED: |
|
76 | - $user_links[] = array( |
|
77 | - 'title' => bts('Remove friend'), |
|
78 | - 'href' => "flag/confirm/unfriend/friend/{$account->uid}" |
|
79 | - ); |
|
80 | - break; |
|
81 | - case FLAG_FRIEND_PENDING: |
|
82 | - $user_links[] = array( |
|
83 | - 'title' => bts('Cancel friend request'), |
|
84 | - 'href' => "flag/confirm/unflag/friend/{$account->uid}" |
|
85 | - ); |
|
86 | - break; |
|
87 | - case FLAG_FRIEND_APPROVAL: |
|
88 | - $user_links[] = array( |
|
89 | - 'title' => bts('Approve friend request'), |
|
90 | - 'href' => "flag/confirm/flag/friend/{$account->uid}" |
|
91 | - ); |
|
92 | - break; |
|
93 | - case FLAG_FRIEND_UNFLAGGED: |
|
94 | - default: |
|
95 | - $user_links[] = array( |
|
96 | - 'title' => bts('Add as friend'), |
|
97 | - 'href' => "flag/confirm/flag/friend/{$account->uid}" |
|
98 | - ); |
|
99 | - } |
|
70 | +if (module_exists('friends')) { |
|
71 | + $flag = flag_get_flag('friend'); |
|
72 | + $friend_status = flag_friend_determine_friend_status($flag, $account->uid, $user->uid); |
|
73 | + switch ($friend_status) { |
|
74 | + case FLAG_FRIEND_BOTH: |
|
75 | + case FLAG_FRIEND_FLAGGED: |
|
76 | + $user_links[] = array( |
|
77 | + 'title' => bts('Remove friend'), |
|
78 | + 'href' => "flag/confirm/unfriend/friend/{$account->uid}" |
|
79 | + ); |
|
80 | + break; |
|
81 | + case FLAG_FRIEND_PENDING: |
|
82 | + $user_links[] = array( |
|
83 | + 'title' => bts('Cancel friend request'), |
|
84 | + 'href' => "flag/confirm/unflag/friend/{$account->uid}" |
|
85 | + ); |
|
86 | + break; |
|
87 | + case FLAG_FRIEND_APPROVAL: |
|
88 | + $user_links[] = array( |
|
89 | + 'title' => bts('Approve friend request'), |
|
90 | + 'href' => "flag/confirm/flag/friend/{$account->uid}" |
|
91 | + ); |
|
92 | + break; |
|
93 | + case FLAG_FRIEND_UNFLAGGED: |
|
94 | + default: |
|
95 | + $user_links[] = array( |
|
96 | + 'title' => bts('Add as friend'), |
|
97 | + 'href' => "flag/confirm/flag/friend/{$account->uid}" |
|
98 | + ); |
|
99 | + } |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | if (user_access('assign community member role') |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | |
18 | 18 | function content_help($path, $arg) { |
19 | 19 | switch ($path) { |
20 | - case 'admin/help#content': |
|
21 | - $output = '<p>'. t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array('@content-types' => url('admin/content/types'), '@node-help' => url('admin/help/node'))) .'</p>'; |
|
22 | - $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
23 | - $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
24 | - $output .= '<ul>'; |
|
25 | - $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
26 | - $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
27 | - $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
28 | - $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
29 | - $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
30 | - $output .= '</ul>'; |
|
31 | - $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
32 | - return $output; |
|
20 | + case 'admin/help#content': |
|
21 | + $output = '<p>'. t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array('@content-types' => url('admin/content/types'), '@node-help' => url('admin/help/node'))) .'</p>'; |
|
22 | + $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
23 | + $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
24 | + $output .= '<ul>'; |
|
25 | + $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
26 | + $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
27 | + $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
28 | + $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
29 | + $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
30 | + $output .= '</ul>'; |
|
31 | + $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
32 | + return $output; |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -553,27 +553,27 @@ discard block |
||
553 | 553 | */ |
554 | 554 | function content_notify($op, $module) { |
555 | 555 | switch ($op) { |
556 | - case 'install': |
|
557 | - content_clear_type_cache(); |
|
558 | - break; |
|
559 | - case 'uninstall': |
|
560 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
561 | - content_module_delete($module); |
|
562 | - break; |
|
563 | - case 'enable': |
|
564 | - content_associate_fields($module); |
|
565 | - content_clear_type_cache(); |
|
566 | - break; |
|
567 | - case 'disable': |
|
568 | - // When CCK modules are disabled before content module's update is run |
|
569 | - // to add the active column, we can't do this. |
|
570 | - if (variable_get('content_schema_version', -1) < 6007) { |
|
571 | - return FALSE; |
|
572 | - } |
|
573 | - db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
574 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
575 | - content_clear_type_cache(TRUE); |
|
576 | - break; |
|
556 | + case 'install': |
|
557 | + content_clear_type_cache(); |
|
558 | + break; |
|
559 | + case 'uninstall': |
|
560 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
561 | + content_module_delete($module); |
|
562 | + break; |
|
563 | + case 'enable': |
|
564 | + content_associate_fields($module); |
|
565 | + content_clear_type_cache(); |
|
566 | + break; |
|
567 | + case 'disable': |
|
568 | + // When CCK modules are disabled before content module's update is run |
|
569 | + // to add the active column, we can't do this. |
|
570 | + if (variable_get('content_schema_version', -1) < 6007) { |
|
571 | + return FALSE; |
|
572 | + } |
|
573 | + db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
574 | + db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
575 | + content_clear_type_cache(TRUE); |
|
576 | + break; |
|
577 | 577 | } |
578 | 578 | } |
579 | 579 | |
@@ -685,38 +685,53 @@ discard block |
||
685 | 685 | */ |
686 | 686 | function content_field($op, &$node, $field, &$items, $teaser, $page) { |
687 | 687 | switch ($op) { |
688 | - case 'validate': |
|
689 | - // TODO: here we could validate that the number of multiple data is correct ? |
|
690 | - // We're controlling the number of fields to fill out and saving empty |
|
691 | - // ones if a specified number is requested, so no reason to do any validation |
|
692 | - // here right now, but if later create a method to indicate whether |
|
693 | - // 'required' means all values must be filled out, we can come back |
|
694 | - // here and check that they're not empty. |
|
695 | - break; |
|
696 | - |
|
697 | - case 'presave': |
|
698 | - if (!empty($node->devel_generate)) { |
|
699 | - include_once('./'. drupal_get_path('module', 'content') .'/includes/content.devel.inc'); |
|
700 | - content_generate_fields($node, $field); |
|
701 | - $items = $node->{$field['field_name']}; |
|
702 | - } |
|
688 | + case 'validate': |
|
689 | + // TODO: here we could validate that the number of multiple data is correct ? |
|
690 | + // We're controlling the number of fields to fill out and saving empty |
|
691 | + // ones if a specified number is requested, so no reason to do any validation |
|
692 | + // here right now, but if later create a method to indicate whether |
|
693 | + // 'required' means all values must be filled out, we can come back |
|
694 | + // here and check that they're not empty. |
|
695 | + break; |
|
696 | + |
|
697 | + case 'presave': |
|
698 | + if (!empty($node->devel_generate)) { |
|
699 | + include_once('./'. drupal_get_path('module', 'content') .'/includes/content.devel.inc'); |
|
700 | + content_generate_fields($node, $field); |
|
701 | + $items = $node->{$field['field_name']}; |
|
702 | + } |
|
703 | 703 | |
704 | - // Manual node_save calls might not have all fields filled in. |
|
705 | - // On node insert, we need to make sure all tables get at least an empty |
|
706 | - // record, or subsequent edits, using drupal_write_record() in update mode, |
|
707 | - // won't insert any data. |
|
708 | - // Missing fields on node update are handled in content_storage(). |
|
709 | - if (empty($items) && !isset($node->nid)) { |
|
710 | - foreach (array_keys($field['columns']) as $column) { |
|
711 | - $items[0][$column] = NULL; |
|
712 | - } |
|
713 | - $node->$field['field_name'] = $items; |
|
704 | + // Manual node_save calls might not have all fields filled in. |
|
705 | + // On node insert, we need to make sure all tables get at least an empty |
|
706 | + // record, or subsequent edits, using drupal_write_record() in update mode, |
|
707 | + // won't insert any data. |
|
708 | + // Missing fields on node update are handled in content_storage(). |
|
709 | + if (empty($items) && !isset($node->nid)) { |
|
710 | + foreach (array_keys($field['columns']) as $column) { |
|
711 | + $items[0][$column] = NULL; |
|
714 | 712 | } |
713 | + $node->$field['field_name'] = $items; |
|
714 | + } |
|
715 | + |
|
716 | + // If there was an AHAH add more button in this field, don't save it. |
|
717 | + // TODO: is it still needed ? |
|
718 | + unset($items[$field['field_name'] .'_add_more']); |
|
719 | + |
|
720 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
721 | + // Reorder items to account for drag-n-drop reordering. |
|
722 | + $items = _content_sort_items($field, $items); |
|
723 | + } |
|
724 | + |
|
725 | + // Filter out empty values. |
|
726 | + $items = content_set_empty($field, $items); |
|
727 | + |
|
728 | + break; |
|
715 | 729 | |
716 | - // If there was an AHAH add more button in this field, don't save it. |
|
717 | - // TODO: is it still needed ? |
|
718 | - unset($items[$field['field_name'] .'_add_more']); |
|
730 | + case 'view': |
|
731 | + $addition = array(); |
|
719 | 732 | |
733 | + // Previewed nodes bypass the 'presave' op, so we need to some massaging. |
|
734 | + if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
720 | 735 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
721 | 736 | // Reorder items to account for drag-n-drop reordering. |
722 | 737 | $items = _content_sort_items($field, $items); |
@@ -724,166 +739,151 @@ discard block |
||
724 | 739 | |
725 | 740 | // Filter out empty values. |
726 | 741 | $items = content_set_empty($field, $items); |
742 | + } |
|
727 | 743 | |
728 | - break; |
|
729 | - |
|
730 | - case 'view': |
|
731 | - $addition = array(); |
|
744 | + // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
745 | + if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
746 | + $context = $teaser ? 'teaser' : 'full'; |
|
747 | + } |
|
748 | + else { |
|
749 | + $context = $node->build_mode; |
|
750 | + } |
|
751 | + // The field may be missing info for $contexts added by modules |
|
752 | + // enabled after the field was last edited. |
|
753 | + $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
|
754 | + if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
755 | + $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
|
756 | + $single = (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE); |
|
757 | + |
|
758 | + $label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above'; |
|
759 | + // Do not include field labels when indexing content. |
|
760 | + if ($context == NODE_BUILD_SEARCH_INDEX) { |
|
761 | + $label_display = 'hidden'; |
|
762 | + } |
|
732 | 763 | |
733 | - // Previewed nodes bypass the 'presave' op, so we need to some massaging. |
|
734 | - if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
735 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
736 | - // Reorder items to account for drag-n-drop reordering. |
|
737 | - $items = _content_sort_items($field, $items); |
|
738 | - } |
|
764 | + $element = array( |
|
765 | + '#type' => 'content_field', |
|
766 | + '#title' => check_plain(t($field['widget']['label'])), |
|
767 | + '#field_name' => $field['field_name'], |
|
768 | + '#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node), |
|
769 | + '#label_display' => $label_display, |
|
770 | + '#node' => $node, |
|
771 | + '#teaser' => $teaser, |
|
772 | + '#page' => $page, |
|
773 | + '#context' => $context, |
|
774 | + '#single' => $single, |
|
775 | + 'items' => array(), |
|
776 | + ); |
|
739 | 777 | |
740 | - // Filter out empty values. |
|
741 | - $items = content_set_empty($field, $items); |
|
778 | + // Fill-in items. |
|
779 | + foreach ($items as $delta => $item) { |
|
780 | + $element['items'][$delta] = array( |
|
781 | + '#item' => $item, |
|
782 | + '#weight' => $delta, |
|
783 | + ); |
|
742 | 784 | } |
743 | 785 | |
744 | - // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
745 | - if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
746 | - $context = $teaser ? 'teaser' : 'full'; |
|
786 | + // Append formatter information either on each item ('single-value' formatter) |
|
787 | + // or at the upper 'items' level ('multiple-value' formatter) |
|
788 | + $format_info = array( |
|
789 | + '#theme' => $theme, |
|
790 | + '#field_name' => $field['field_name'], |
|
791 | + '#type_name' => $node->type, |
|
792 | + '#formatter' => $formatter_name, |
|
793 | + '#node' => $node, |
|
794 | + ); |
|
795 | + if ($single) { |
|
796 | + foreach ($items as $delta => $item) { |
|
797 | + $element['items'][$delta] += $format_info; |
|
798 | + $element['items'][$delta]['#item']['#delta'] = $delta; |
|
799 | + } |
|
747 | 800 | } |
748 | 801 | else { |
749 | - $context = $node->build_mode; |
|
802 | + $element['items'] += $format_info; |
|
750 | 803 | } |
751 | - // The field may be missing info for $contexts added by modules |
|
752 | - // enabled after the field was last edited. |
|
753 | - $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
|
754 | - if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
755 | - $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
|
756 | - $single = (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE); |
|
757 | - |
|
758 | - $label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above'; |
|
759 | - // Do not include field labels when indexing content. |
|
760 | - if ($context == NODE_BUILD_SEARCH_INDEX) { |
|
761 | - $label_display = 'hidden'; |
|
762 | - } |
|
763 | 804 | |
764 | - $element = array( |
|
765 | - '#type' => 'content_field', |
|
766 | - '#title' => check_plain(t($field['widget']['label'])), |
|
767 | - '#field_name' => $field['field_name'], |
|
768 | - '#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node), |
|
769 | - '#label_display' => $label_display, |
|
770 | - '#node' => $node, |
|
771 | - '#teaser' => $teaser, |
|
772 | - '#page' => $page, |
|
773 | - '#context' => $context, |
|
774 | - '#single' => $single, |
|
775 | - 'items' => array(), |
|
776 | - ); |
|
805 | + // The wrapper lets us get the themed output for the whole field |
|
806 | + // to populate the $FIELD_NAME_rendered variable for node templates, |
|
807 | + // and hide it from the $content variable if needed. |
|
808 | + // See 'preprocess_node' op and theme_content_field_wrapper()? |
|
809 | + $wrapper = array( |
|
810 | + 'field' => $element, |
|
811 | + '#weight' => $field['widget']['weight'], |
|
812 | + '#post_render' => array('content_field_wrapper_post_render'), |
|
813 | + '#field_name' => $field['field_name'], |
|
814 | + '#type_name' => $node->type, |
|
815 | + '#context' => $context, |
|
816 | + ); |
|
777 | 817 | |
778 | - // Fill-in items. |
|
779 | - foreach ($items as $delta => $item) { |
|
780 | - $element['items'][$delta] = array( |
|
781 | - '#item' => $item, |
|
782 | - '#weight' => $delta, |
|
783 | - ); |
|
784 | - } |
|
818 | + $addition = array($field['field_name'] => $wrapper); |
|
819 | + } |
|
820 | + return $addition; |
|
821 | + |
|
822 | + case 'alter': |
|
823 | + // Add back the formatted values in the 'view' element, |
|
824 | + // so that tokens and node templates can use it. |
|
825 | + // Note: Doing this in 'preprocess_node' breaks token integration. |
|
826 | + |
|
827 | + // The location of the field's rendered output depends on whether the |
|
828 | + // field is in a fieldgroup or not. |
|
829 | + $wrapper = NULL; |
|
830 | + if (isset($node->content[$field['field_name']])) { |
|
831 | + $wrapper = $node->content[$field['field_name']]; |
|
832 | + } |
|
833 | + elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
834 | + $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
|
835 | + } |
|
785 | 836 | |
786 | - // Append formatter information either on each item ('single-value' formatter) |
|
787 | - // or at the upper 'items' level ('multiple-value' formatter) |
|
788 | - $format_info = array( |
|
789 | - '#theme' => $theme, |
|
790 | - '#field_name' => $field['field_name'], |
|
791 | - '#type_name' => $node->type, |
|
792 | - '#formatter' => $formatter_name, |
|
793 | - '#node' => $node, |
|
794 | - ); |
|
795 | - if ($single) { |
|
796 | - foreach ($items as $delta => $item) { |
|
797 | - $element['items'][$delta] += $format_info; |
|
798 | - $element['items'][$delta]['#item']['#delta'] = $delta; |
|
837 | + if ($wrapper) { |
|
838 | + $element = $wrapper['field']; |
|
839 | + // '#single' is not set if the field is hidden or inaccessible. |
|
840 | + if (isset($element['#single'])) { |
|
841 | + if (!empty($element['#single'])) { |
|
842 | + // Single value formatter. |
|
843 | + foreach (element_children($element['items']) as $delta) { |
|
844 | + // '#chilren' is not set if the field is empty. |
|
845 | + $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
799 | 846 | } |
800 | 847 | } |
801 | - else { |
|
802 | - $element['items'] += $format_info; |
|
848 | + elseif (isset($element['items']['#children'])) { |
|
849 | + // Multiple values formatter. |
|
850 | + $items[0]['view'] = $element['items']['#children']; |
|
803 | 851 | } |
804 | - |
|
805 | - // The wrapper lets us get the themed output for the whole field |
|
806 | - // to populate the $FIELD_NAME_rendered variable for node templates, |
|
807 | - // and hide it from the $content variable if needed. |
|
808 | - // See 'preprocess_node' op and theme_content_field_wrapper()? |
|
809 | - $wrapper = array( |
|
810 | - 'field' => $element, |
|
811 | - '#weight' => $field['widget']['weight'], |
|
812 | - '#post_render' => array('content_field_wrapper_post_render'), |
|
813 | - '#field_name' => $field['field_name'], |
|
814 | - '#type_name' => $node->type, |
|
815 | - '#context' => $context, |
|
816 | - ); |
|
817 | - |
|
818 | - $addition = array($field['field_name'] => $wrapper); |
|
819 | 852 | } |
820 | - return $addition; |
|
821 | - |
|
822 | - case 'alter': |
|
823 | - // Add back the formatted values in the 'view' element, |
|
824 | - // so that tokens and node templates can use it. |
|
825 | - // Note: Doing this in 'preprocess_node' breaks token integration. |
|
826 | - |
|
827 | - // The location of the field's rendered output depends on whether the |
|
828 | - // field is in a fieldgroup or not. |
|
829 | - $wrapper = NULL; |
|
830 | - if (isset($node->content[$field['field_name']])) { |
|
831 | - $wrapper = $node->content[$field['field_name']]; |
|
832 | - } |
|
833 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
834 | - $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
|
835 | - } |
|
836 | - |
|
837 | - if ($wrapper) { |
|
838 | - $element = $wrapper['field']; |
|
839 | - // '#single' is not set if the field is hidden or inaccessible. |
|
840 | - if (isset($element['#single'])) { |
|
841 | - if (!empty($element['#single'])) { |
|
842 | - // Single value formatter. |
|
843 | - foreach (element_children($element['items']) as $delta) { |
|
844 | - // '#chilren' is not set if the field is empty. |
|
845 | - $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
846 | - } |
|
847 | - } |
|
848 | - elseif (isset($element['items']['#children'])) { |
|
849 | - // Multiple values formatter. |
|
850 | - $items[0]['view'] = $element['items']['#children']; |
|
851 | - } |
|
852 | - } |
|
853 | - else { |
|
854 | - // Hidden or inaccessible field. |
|
855 | - $items[0]['view'] = ''; |
|
856 | - } |
|
853 | + else { |
|
854 | + // Hidden or inaccessible field. |
|
855 | + $items[0]['view'] = ''; |
|
857 | 856 | } |
858 | - break; |
|
857 | + } |
|
858 | + break; |
|
859 | 859 | |
860 | - case 'preprocess_node': |
|
861 | - // Add $FIELD_NAME_rendered variables. |
|
862 | - $addition = array(); |
|
860 | + case 'preprocess_node': |
|
861 | + // Add $FIELD_NAME_rendered variables. |
|
862 | + $addition = array(); |
|
863 | 863 | |
864 | - // The location of the field's rendered output depends on whether the |
|
865 | - // field is in a fieldgroup or not. |
|
866 | - $wrapper = NULL; |
|
867 | - if (isset($node->content[$field['field_name']])) { |
|
868 | - $wrapper = $node->content[$field['field_name']]; |
|
869 | - } |
|
870 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
871 | - $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
|
872 | - } |
|
864 | + // The location of the field's rendered output depends on whether the |
|
865 | + // field is in a fieldgroup or not. |
|
866 | + $wrapper = NULL; |
|
867 | + if (isset($node->content[$field['field_name']])) { |
|
868 | + $wrapper = $node->content[$field['field_name']]; |
|
869 | + } |
|
870 | + elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
871 | + $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
|
872 | + } |
|
873 | 873 | |
874 | - if ($wrapper) { |
|
875 | - // '#chilren' is not set if the field is empty. |
|
876 | - $addition[$field['field_name'] .'_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : ''; |
|
877 | - } |
|
874 | + if ($wrapper) { |
|
875 | + // '#chilren' is not set if the field is empty. |
|
876 | + $addition[$field['field_name'] .'_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : ''; |
|
877 | + } |
|
878 | 878 | |
879 | - return $addition; |
|
879 | + return $addition; |
|
880 | 880 | |
881 | - case 'prepare translation': |
|
882 | - $addition = array(); |
|
883 | - if (isset($node->translation_source->$field['field_name'])) { |
|
884 | - $addition[$field['field_name']] = $node->translation_source->$field['field_name']; |
|
885 | - } |
|
886 | - return $addition; |
|
881 | + case 'prepare translation': |
|
882 | + $addition = array(); |
|
883 | + if (isset($node->translation_source->$field['field_name'])) { |
|
884 | + $addition[$field['field_name']] = $node->translation_source->$field['field_name']; |
|
885 | + } |
|
886 | + return $addition; |
|
887 | 887 | } |
888 | 888 | } |
889 | 889 | |
@@ -974,122 +974,122 @@ discard block |
||
974 | 974 | $type = content_types($type_name); |
975 | 975 | |
976 | 976 | switch ($op) { |
977 | - case 'load': |
|
978 | - // OPTIMIZE: load all non multiple fields in a single JOIN query ? |
|
979 | - // warning: 61-join limit in MySQL ? |
|
980 | - $additions = array(); |
|
981 | - // For each table used by this content type, |
|
982 | - foreach ($type['tables'] as $table) { |
|
983 | - $schema = drupal_get_schema($table); |
|
984 | - // The per-type table might not have any fields actually stored in it. |
|
985 | - if (!$schema['content fields']) { |
|
986 | - continue; |
|
987 | - } |
|
988 | - $query = 'SELECT * FROM {'. $table .'} WHERE vid = %d'; |
|
989 | - |
|
990 | - // If we're loading a table for a multiple field, |
|
991 | - // we fetch all rows (values) ordered by delta, |
|
992 | - // else we only fetch one row. |
|
993 | - $result = isset($schema['fields']['delta']) ? db_query($query .' ORDER BY delta', $node->vid) : db_query_range($query, $node->vid, 0, 1); |
|
994 | - |
|
995 | - // For each table row, populate the fields. |
|
996 | - while ($row = db_fetch_array($result)) { |
|
997 | - // For each field stored in the table, add the field item. |
|
998 | - foreach ($schema['content fields'] as $field_name) { |
|
999 | - $item = array(); |
|
1000 | - $field = content_fields($field_name, $type_name); |
|
1001 | - $db_info = content_database_info($field); |
|
1002 | - // For each column declared by the field, populate the item. |
|
1003 | - foreach ($db_info['columns'] as $column => $attributes) { |
|
1004 | - $item[$column] = $row[$attributes['column']]; |
|
1005 | - } |
|
1006 | - |
|
1007 | - // Add the item to the field values for the node. |
|
1008 | - if (!isset($additions[$field_name])) { |
|
1009 | - $additions[$field_name] = array(); |
|
1010 | - } |
|
1011 | - $additions[$field_name][] = $item; |
|
1012 | - } |
|
1013 | - } |
|
977 | + case 'load': |
|
978 | + // OPTIMIZE: load all non multiple fields in a single JOIN query ? |
|
979 | + // warning: 61-join limit in MySQL ? |
|
980 | + $additions = array(); |
|
981 | + // For each table used by this content type, |
|
982 | + foreach ($type['tables'] as $table) { |
|
983 | + $schema = drupal_get_schema($table); |
|
984 | + // The per-type table might not have any fields actually stored in it. |
|
985 | + if (!$schema['content fields']) { |
|
986 | + continue; |
|
1014 | 987 | } |
1015 | - return $additions; |
|
988 | + $query = 'SELECT * FROM {'. $table .'} WHERE vid = %d'; |
|
989 | + |
|
990 | + // If we're loading a table for a multiple field, |
|
991 | + // we fetch all rows (values) ordered by delta, |
|
992 | + // else we only fetch one row. |
|
993 | + $result = isset($schema['fields']['delta']) ? db_query($query .' ORDER BY delta', $node->vid) : db_query_range($query, $node->vid, 0, 1); |
|
1016 | 994 | |
1017 | - case 'insert': |
|
1018 | - case 'update': |
|
1019 | - foreach ($type['tables'] as $table) { |
|
1020 | - $schema = drupal_get_schema($table); |
|
1021 | - $record = array(); |
|
995 | + // For each table row, populate the fields. |
|
996 | + while ($row = db_fetch_array($result)) { |
|
997 | + // For each field stored in the table, add the field item. |
|
1022 | 998 | foreach ($schema['content fields'] as $field_name) { |
1023 | - if (isset($node->$field_name)) { |
|
1024 | - $field = content_fields($field_name, $type_name); |
|
1025 | - // Multiple fields need specific handling, we'll deal with them later on. |
|
1026 | - if ($field['multiple']) { |
|
1027 | - continue; |
|
1028 | - } |
|
1029 | - $db_info = content_database_info($field); |
|
1030 | - foreach ($db_info['columns'] as $column => $attributes) { |
|
1031 | - $record[$attributes['column']] = $node->{$field_name}[0][$column]; |
|
1032 | - } |
|
999 | + $item = array(); |
|
1000 | + $field = content_fields($field_name, $type_name); |
|
1001 | + $db_info = content_database_info($field); |
|
1002 | + // For each column declared by the field, populate the item. |
|
1003 | + foreach ($db_info['columns'] as $column => $attributes) { |
|
1004 | + $item[$column] = $row[$attributes['column']]; |
|
1033 | 1005 | } |
1006 | + |
|
1007 | + // Add the item to the field values for the node. |
|
1008 | + if (!isset($additions[$field_name])) { |
|
1009 | + $additions[$field_name] = array(); |
|
1010 | + } |
|
1011 | + $additions[$field_name][] = $item; |
|
1034 | 1012 | } |
1035 | - // $record might be empty because |
|
1036 | - // - the table stores a multiple field : |
|
1037 | - // we do nothing, this is handled later on |
|
1038 | - // - this is the per-type table and no field is actually stored in it : |
|
1039 | - // we still store the nid and vid |
|
1040 | - if (count($record) || empty($schema['content fields'])) { |
|
1041 | - $record['nid'] = $node->nid; |
|
1042 | - $record['vid'] = $node->vid; |
|
1043 | - // Can't rely on the insert/update op of the node to decide if this |
|
1044 | - // is an insert or an update, a node or revision may have existed |
|
1045 | - // before any fields were created, so there may not be an entry here. |
|
1046 | - |
|
1047 | - // TODO - should we auto create an entry for all existing nodes when |
|
1048 | - // fields are added to content types -- either a NULL value |
|
1049 | - // or the default value? May need to offer the user an option of |
|
1050 | - // how to handle that. |
|
1051 | - if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
1052 | - content_write_record($table, $record, array('vid')); |
|
1013 | + } |
|
1014 | + } |
|
1015 | + return $additions; |
|
1016 | + |
|
1017 | + case 'insert': |
|
1018 | + case 'update': |
|
1019 | + foreach ($type['tables'] as $table) { |
|
1020 | + $schema = drupal_get_schema($table); |
|
1021 | + $record = array(); |
|
1022 | + foreach ($schema['content fields'] as $field_name) { |
|
1023 | + if (isset($node->$field_name)) { |
|
1024 | + $field = content_fields($field_name, $type_name); |
|
1025 | + // Multiple fields need specific handling, we'll deal with them later on. |
|
1026 | + if ($field['multiple']) { |
|
1027 | + continue; |
|
1053 | 1028 | } |
1054 | - else { |
|
1055 | - content_write_record($table, $record); |
|
1029 | + $db_info = content_database_info($field); |
|
1030 | + foreach ($db_info['columns'] as $column => $attributes) { |
|
1031 | + $record[$attributes['column']] = $node->{$field_name}[0][$column]; |
|
1056 | 1032 | } |
1057 | 1033 | } |
1058 | 1034 | } |
1035 | + // $record might be empty because |
|
1036 | + // - the table stores a multiple field : |
|
1037 | + // we do nothing, this is handled later on |
|
1038 | + // - this is the per-type table and no field is actually stored in it : |
|
1039 | + // we still store the nid and vid |
|
1040 | + if (count($record) || empty($schema['content fields'])) { |
|
1041 | + $record['nid'] = $node->nid; |
|
1042 | + $record['vid'] = $node->vid; |
|
1043 | + // Can't rely on the insert/update op of the node to decide if this |
|
1044 | + // is an insert or an update, a node or revision may have existed |
|
1045 | + // before any fields were created, so there may not be an entry here. |
|
1046 | + |
|
1047 | + // TODO - should we auto create an entry for all existing nodes when |
|
1048 | + // fields are added to content types -- either a NULL value |
|
1049 | + // or the default value? May need to offer the user an option of |
|
1050 | + // how to handle that. |
|
1051 | + if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
1052 | + content_write_record($table, $record, array('vid')); |
|
1053 | + } |
|
1054 | + else { |
|
1055 | + content_write_record($table, $record); |
|
1056 | + } |
|
1057 | + } |
|
1058 | + } |
|
1059 | 1059 | |
1060 | - // Handle multiple fields. |
|
1061 | - foreach ($type['fields'] as $field) { |
|
1062 | - if ($field['multiple'] && isset($node->$field['field_name'])) { |
|
1063 | - $db_info = content_database_info($field); |
|
1064 | - // Delete and insert, rather than update, in case a value was added. |
|
1065 | - if ($op == 'update') { |
|
1066 | - db_query('DELETE FROM {'. $db_info['table'] .'} WHERE vid = %d', $node->vid); |
|
1067 | - } |
|
1068 | - foreach ($node->$field['field_name'] as $delta => $item) { |
|
1069 | - $record = array(); |
|
1070 | - foreach ($db_info['columns'] as $column => $attributes) { |
|
1071 | - $record[$attributes['column']] = $item[$column]; |
|
1072 | - } |
|
1073 | - $record['nid'] = $node->nid; |
|
1074 | - $record['vid'] = $node->vid; |
|
1075 | - $record['delta'] = $delta; |
|
1076 | - content_write_record($db_info['table'], $record); |
|
1060 | + // Handle multiple fields. |
|
1061 | + foreach ($type['fields'] as $field) { |
|
1062 | + if ($field['multiple'] && isset($node->$field['field_name'])) { |
|
1063 | + $db_info = content_database_info($field); |
|
1064 | + // Delete and insert, rather than update, in case a value was added. |
|
1065 | + if ($op == 'update') { |
|
1066 | + db_query('DELETE FROM {'. $db_info['table'] .'} WHERE vid = %d', $node->vid); |
|
1067 | + } |
|
1068 | + foreach ($node->$field['field_name'] as $delta => $item) { |
|
1069 | + $record = array(); |
|
1070 | + foreach ($db_info['columns'] as $column => $attributes) { |
|
1071 | + $record[$attributes['column']] = $item[$column]; |
|
1077 | 1072 | } |
1073 | + $record['nid'] = $node->nid; |
|
1074 | + $record['vid'] = $node->vid; |
|
1075 | + $record['delta'] = $delta; |
|
1076 | + content_write_record($db_info['table'], $record); |
|
1078 | 1077 | } |
1079 | 1078 | } |
1080 | - break; |
|
1079 | + } |
|
1080 | + break; |
|
1081 | 1081 | |
1082 | - case 'delete': |
|
1083 | - foreach ($type['tables'] as $table) { |
|
1084 | - db_query('DELETE FROM {'. $table .'} WHERE nid = %d', $node->nid); |
|
1085 | - } |
|
1086 | - break; |
|
1082 | + case 'delete': |
|
1083 | + foreach ($type['tables'] as $table) { |
|
1084 | + db_query('DELETE FROM {'. $table .'} WHERE nid = %d', $node->nid); |
|
1085 | + } |
|
1086 | + break; |
|
1087 | 1087 | |
1088 | - case 'delete revision': |
|
1089 | - foreach ($type['tables'] as $table) { |
|
1090 | - db_query('DELETE FROM {'. $table .'} WHERE vid = %d', $node->vid); |
|
1091 | - } |
|
1092 | - break; |
|
1088 | + case 'delete revision': |
|
1089 | + foreach ($type['tables'] as $table) { |
|
1090 | + db_query('DELETE FROM {'. $table .'} WHERE vid = %d', $node->vid); |
|
1091 | + } |
|
1092 | + break; |
|
1093 | 1093 | } |
1094 | 1094 | } |
1095 | 1095 | |
@@ -1526,18 +1526,18 @@ discard block |
||
1526 | 1526 | */ |
1527 | 1527 | function content_node_type($op, $info) { |
1528 | 1528 | switch ($op) { |
1529 | - case 'insert': |
|
1530 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
1531 | - content_type_create($info); |
|
1532 | - break; |
|
1533 | - case 'update': |
|
1534 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
1535 | - content_type_update($info); |
|
1536 | - break; |
|
1537 | - case 'delete': |
|
1538 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
1539 | - content_type_delete($info); |
|
1540 | - break; |
|
1529 | + case 'insert': |
|
1530 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
1531 | + content_type_create($info); |
|
1532 | + break; |
|
1533 | + case 'update': |
|
1534 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
1535 | + content_type_update($info); |
|
1536 | + break; |
|
1537 | + case 'delete': |
|
1538 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
1539 | + content_type_delete($info); |
|
1540 | + break; |
|
1541 | 1541 | } |
1542 | 1542 | } |
1543 | 1543 | |
@@ -1994,14 +1994,14 @@ discard block |
||
1994 | 1994 | |
1995 | 1995 | $name = str_replace('-', '_', $name); |
1996 | 1996 | switch ("$version-$storage") { |
1997 | - case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
1998 | - return "node_$name"; |
|
1999 | - case '0-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
2000 | - return "node_data_$name"; |
|
2001 | - case '1003-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
2002 | - return "content_type_$name"; |
|
2003 | - case '1003-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
2004 | - return "content_$name"; |
|
1997 | + case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
1998 | + return "node_$name"; |
|
1999 | + case '0-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
2000 | + return "node_data_$name"; |
|
2001 | + case '1003-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
2002 | + return "content_type_$name"; |
|
2003 | + case '1003-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
2004 | + return "content_$name"; |
|
2005 | 2005 | } |
2006 | 2006 | } |
2007 | 2007 | |
@@ -2153,13 +2153,13 @@ discard block |
||
2153 | 2153 | */ |
2154 | 2154 | function content_callback($entity, $op, $field) { |
2155 | 2155 | switch ($entity) { |
2156 | - case 'field': |
|
2157 | - $info = module_invoke($field['module'], "field_info"); |
|
2158 | - return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
2156 | + case 'field': |
|
2157 | + $info = module_invoke($field['module'], "field_info"); |
|
2158 | + return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
2159 | 2159 | |
2160 | - case 'widget': |
|
2161 | - $info = module_invoke($field['widget']['module'], "widget_info"); |
|
2162 | - return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
2160 | + case 'widget': |
|
2161 | + $info = module_invoke($field['widget']['module'], "widget_info"); |
|
2162 | + return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
2163 | 2163 | } |
2164 | 2164 | } |
2165 | 2165 | |
@@ -2183,18 +2183,18 @@ discard block |
||
2183 | 2183 | */ |
2184 | 2184 | function content_handle($entity, $op, $object) { |
2185 | 2185 | switch ($entity) { |
2186 | - case 'field': |
|
2187 | - $info = module_invoke($object['module'], "field_info"); |
|
2188 | - return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE; |
|
2189 | - |
|
2190 | - case 'widget': |
|
2191 | - $info = module_invoke($object['widget']['module'], "widget_info"); |
|
2192 | - return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE; |
|
2193 | - |
|
2194 | - case 'formatter': |
|
2195 | - // Much simpler, formatters arrays *are* the 'formatter_info' itself. |
|
2196 | - // We let content_handle deal with them only for code consistency. |
|
2197 | - return isset($object[$op]) ? $object[$op] : CONTENT_HANDLE_CORE; |
|
2186 | + case 'field': |
|
2187 | + $info = module_invoke($object['module'], "field_info"); |
|
2188 | + return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE; |
|
2189 | + |
|
2190 | + case 'widget': |
|
2191 | + $info = module_invoke($object['widget']['module'], "widget_info"); |
|
2192 | + return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE; |
|
2193 | + |
|
2194 | + case 'formatter': |
|
2195 | + // Much simpler, formatters arrays *are* the 'formatter_info' itself. |
|
2196 | + // We let content_handle deal with them only for code consistency. |
|
2197 | + return isset($object[$op]) ? $object[$op] : CONTENT_HANDLE_CORE; |
|
2198 | 2198 | } |
2199 | 2199 | } |
2200 | 2200 |
@@ -97,89 +97,89 @@ discard block |
||
97 | 97 | $form['#prefix'] = t('This form will process a content type and one or more fields from that type and export the settings. The export created by this process can be copied and pasted as an import into the current or any other database. The import will add the fields to an existing content type or create a new content type that includes the selected fields.'); |
98 | 98 | |
99 | 99 | switch ($step) { |
100 | - case 1: // Select a content type. |
|
101 | - $types = content_copy_types(); |
|
102 | - $form['type_name'] = array( |
|
103 | - '#title' => t('Types'), |
|
104 | - '#type' => 'radios', |
|
105 | - '#options' => $types, |
|
106 | - '#description' => t('Select the content type to export.'), |
|
107 | - ); |
|
108 | - break; |
|
109 | - |
|
110 | - case 2: // Select groups and fields. |
|
111 | - $form['type_name'] = array( |
|
112 | - '#type' => 'hidden', |
|
113 | - '#value' => $type_name, |
|
114 | - ); |
|
115 | - |
|
116 | - $form += array( |
|
117 | - '#fields' => $exportable_fields, |
|
118 | - '#groups' => array_keys($groups), |
|
119 | - ); |
|
120 | - |
|
121 | - $fields_options = $groups_options = array(); |
|
122 | - |
|
123 | - // Fields. |
|
124 | - foreach ($exportable_fields as $field_name) { |
|
125 | - $field = content_fields($field_name, $type_name); |
|
126 | - $fields_options[$field_name] = ''; |
|
127 | - $weight = $field['widget']['weight']; |
|
128 | - $form[$field_name] = array( |
|
129 | - 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
130 | - 'field_name' => array('#value' => $field['field_name']), |
|
131 | - 'type' => array('#value' => $field['type']), |
|
132 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
133 | - 'parent' => array('#type' => 'value', '#value' => ''), |
|
134 | - '#row_type' => 'field', |
|
135 | - ); |
|
136 | - } |
|
137 | - $form['fields'] = array( |
|
138 | - '#type' => 'checkboxes', |
|
139 | - '#options' => $fields_options, |
|
140 | - '#default_value' => array_keys($fields_options), |
|
141 | - ); |
|
142 | - |
|
143 | - // Groups. |
|
144 | - foreach ($groups as $name => $group) { |
|
145 | - $groups_options[$name] = ''; |
|
146 | - $weight = $group['weight']; |
|
147 | - $form[$name] = array( |
|
148 | - 'human_name' => array('#value' => check_plain($group['label'])), |
|
149 | - 'group_name' => array('#value' => $group['group_name']), |
|
150 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
151 | - '#row_type' => 'group', |
|
152 | - ); |
|
153 | - foreach ($group['fields'] as $field_name => $field) { |
|
154 | - // Do nothing for non-exportable (inactive) fields. |
|
155 | - if (isset($form[$field_name])) { |
|
156 | - $form[$field_name]['parent']['#value'] = $name; |
|
157 | - } |
|
158 | - } |
|
159 | - } |
|
160 | - if ($groups) { |
|
161 | - $form['groups'] = array( |
|
162 | - '#type' => 'checkboxes', |
|
163 | - '#options' => $groups_options, |
|
164 | - '#default_value' => array_keys($groups_options), |
|
165 | - ); |
|
166 | - } |
|
167 | - break; |
|
168 | - |
|
169 | - case 3: // Display the export macro. |
|
170 | - $GLOBALS['content_copy']['count'] = 0; |
|
171 | - $form['export'] = array( |
|
172 | - '#title' => t('Export data'), |
|
173 | - '#type' => 'textarea', |
|
174 | - '#cols' => 60, |
|
175 | - '#value' => content_copy_export($form_values), |
|
176 | - '#rows' => max(40, $GLOBALS['content_copy']['count']), |
|
177 | - '#description' => t('Copy the export text and paste it into another content type using the import function.'), |
|
178 | - ); |
|
179 | - // The calls to drupal_execute('content_field_edit_form') in |
|
180 | - // content_copy_export() affect the page title, |
|
181 | - drupal_set_title(t('Content types')); |
|
182 | - break; |
|
100 | + case 1: // Select a content type. |
|
101 | + $types = content_copy_types(); |
|
102 | + $form['type_name'] = array( |
|
103 | + '#title' => t('Types'), |
|
104 | + '#type' => 'radios', |
|
105 | + '#options' => $types, |
|
106 | + '#description' => t('Select the content type to export.'), |
|
107 | + ); |
|
108 | + break; |
|
109 | + |
|
110 | + case 2: // Select groups and fields. |
|
111 | + $form['type_name'] = array( |
|
112 | + '#type' => 'hidden', |
|
113 | + '#value' => $type_name, |
|
114 | + ); |
|
115 | + |
|
116 | + $form += array( |
|
117 | + '#fields' => $exportable_fields, |
|
118 | + '#groups' => array_keys($groups), |
|
119 | + ); |
|
120 | + |
|
121 | + $fields_options = $groups_options = array(); |
|
122 | + |
|
123 | + // Fields. |
|
124 | + foreach ($exportable_fields as $field_name) { |
|
125 | + $field = content_fields($field_name, $type_name); |
|
126 | + $fields_options[$field_name] = ''; |
|
127 | + $weight = $field['widget']['weight']; |
|
128 | + $form[$field_name] = array( |
|
129 | + 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
130 | + 'field_name' => array('#value' => $field['field_name']), |
|
131 | + 'type' => array('#value' => $field['type']), |
|
132 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
133 | + 'parent' => array('#type' => 'value', '#value' => ''), |
|
134 | + '#row_type' => 'field', |
|
135 | + ); |
|
136 | + } |
|
137 | + $form['fields'] = array( |
|
138 | + '#type' => 'checkboxes', |
|
139 | + '#options' => $fields_options, |
|
140 | + '#default_value' => array_keys($fields_options), |
|
141 | + ); |
|
142 | + |
|
143 | + // Groups. |
|
144 | + foreach ($groups as $name => $group) { |
|
145 | + $groups_options[$name] = ''; |
|
146 | + $weight = $group['weight']; |
|
147 | + $form[$name] = array( |
|
148 | + 'human_name' => array('#value' => check_plain($group['label'])), |
|
149 | + 'group_name' => array('#value' => $group['group_name']), |
|
150 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
151 | + '#row_type' => 'group', |
|
152 | + ); |
|
153 | + foreach ($group['fields'] as $field_name => $field) { |
|
154 | + // Do nothing for non-exportable (inactive) fields. |
|
155 | + if (isset($form[$field_name])) { |
|
156 | + $form[$field_name]['parent']['#value'] = $name; |
|
157 | + } |
|
158 | + } |
|
159 | + } |
|
160 | + if ($groups) { |
|
161 | + $form['groups'] = array( |
|
162 | + '#type' => 'checkboxes', |
|
163 | + '#options' => $groups_options, |
|
164 | + '#default_value' => array_keys($groups_options), |
|
165 | + ); |
|
166 | + } |
|
167 | + break; |
|
168 | + |
|
169 | + case 3: // Display the export macro. |
|
170 | + $GLOBALS['content_copy']['count'] = 0; |
|
171 | + $form['export'] = array( |
|
172 | + '#title' => t('Export data'), |
|
173 | + '#type' => 'textarea', |
|
174 | + '#cols' => 60, |
|
175 | + '#value' => content_copy_export($form_values), |
|
176 | + '#rows' => max(40, $GLOBALS['content_copy']['count']), |
|
177 | + '#description' => t('Copy the export text and paste it into another content type using the import function.'), |
|
178 | + ); |
|
179 | + // The calls to drupal_execute('content_field_edit_form') in |
|
180 | + // content_copy_export() affect the page title, |
|
181 | + drupal_set_title(t('Content types')); |
|
182 | + break; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | if ($step < 3) { // Omit submit button on the textarea block to display the export data. |
@@ -559,48 +559,48 @@ discard block |
||
559 | 559 | unset($edit['type_name'], $edit['submit'], $edit['delete'], $edit['form_id'], $edit['previous_field']); |
560 | 560 | } |
561 | 561 | switch ($form_id) { |
562 | - case 'node_type_form': |
|
563 | - $subs['type'] = $edit; |
|
564 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
565 | - break; |
|
566 | - |
|
567 | - case 'fieldgroup_group_edit_form': |
|
568 | - $subs['groups'][] = $edit; |
|
569 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
570 | - break; |
|
571 | - |
|
572 | - default: |
|
573 | - if (isset($edit['field_widget_type'])) { |
|
574 | - $tmp = explode('-', $edit['field_widget_type']); |
|
575 | - $field_name = $tmp[0]; |
|
576 | - } |
|
577 | - else { |
|
578 | - $field_name = isset($edit['field_name']) ? $edit['field_name'] : ''; |
|
579 | - } |
|
562 | + case 'node_type_form': |
|
563 | + $subs['type'] = $edit; |
|
564 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
565 | + break; |
|
566 | + |
|
567 | + case 'fieldgroup_group_edit_form': |
|
568 | + $subs['groups'][] = $edit; |
|
569 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
570 | + break; |
|
571 | + |
|
572 | + default: |
|
573 | + if (isset($edit['field_widget_type'])) { |
|
574 | + $tmp = explode('-', $edit['field_widget_type']); |
|
575 | + $field_name = $tmp[0]; |
|
576 | + } |
|
577 | + else { |
|
578 | + $field_name = isset($edit['field_name']) ? $edit['field_name'] : ''; |
|
579 | + } |
|
580 | 580 | |
581 | - // The display settings are being fetched directly from the DB. During import, |
|
582 | - // we'll re-insert the data directly as well. |
|
583 | - // |
|
584 | - $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\''; |
|
585 | - $row_info = db_fetch_array(db_query($query, $field_name)); |
|
586 | - |
|
587 | - // If an error occurs, notify the user. |
|
588 | - if ($db_err = db_error()) { |
|
589 | - drupal_set_message(t("An error occurred when exporting the 'display settings' data for the field %field_name.<br/>The db error is: '%db_err'.", array( |
|
590 | - '%field_name' => $field_name, |
|
591 | - '%db_err' => $db_err |
|
592 | - ))); |
|
593 | - } |
|
594 | - else { |
|
595 | - // The db fetch occurred successfully, unserialize the data blob and |
|
596 | - // insert it into a new "display_settings" field of the data. |
|
597 | - if ($display_settings = unserialize($row_info['display_settings'])) { |
|
598 | - $edit['display_settings'] = $display_settings; |
|
599 | - } |
|
581 | + // The display settings are being fetched directly from the DB. During import, |
|
582 | + // we'll re-insert the data directly as well. |
|
583 | + // |
|
584 | + $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\''; |
|
585 | + $row_info = db_fetch_array(db_query($query, $field_name)); |
|
586 | + |
|
587 | + // If an error occurs, notify the user. |
|
588 | + if ($db_err = db_error()) { |
|
589 | + drupal_set_message(t("An error occurred when exporting the 'display settings' data for the field %field_name.<br/>The db error is: '%db_err'.", array( |
|
590 | + '%field_name' => $field_name, |
|
591 | + '%db_err' => $db_err |
|
592 | + ))); |
|
593 | + } |
|
594 | + else { |
|
595 | + // The db fetch occurred successfully, unserialize the data blob and |
|
596 | + // insert it into a new "display_settings" field of the data. |
|
597 | + if ($display_settings = unserialize($row_info['display_settings'])) { |
|
598 | + $edit['display_settings'] = $display_settings; |
|
600 | 599 | } |
601 | - $subs['fields'][] = $edit; |
|
602 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
603 | - break; |
|
600 | + } |
|
601 | + $subs['fields'][] = $edit; |
|
602 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
603 | + break; |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | $GLOBALS['content_copy']['submissions'] = $subs; |