source: sipes/modules_contrib/cck/includes/content.diff.inc @ 6e81fb4

stableversion-3.0
Last change on this file since 6e81fb4 was dafc8d8, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo el modulo

  • Propiedad mode establecida a 100755
File size: 3.7 KB
Línea 
1<?php
2
3/**
4 * @file hook_diff() implementations for CCK (especially fields).
5 *
6 * These should use a field-hook so the data for the diff is
7 * field-type specific.
8 */
9
10/**
11 * Implementation of hook_diff()
12 */
13function content_diff($old_node, $new_node) {
14  $result = array();
15  // Prevent against invalid 'nodes' built by broken 3rd party code.
16  if (isset($new_node->type)) {
17    $type = content_types($new_node->type);
18    $field_types = _content_field_types();
19    foreach ($type['fields'] as $field) {
20      // Ignore fields the current user is not allowed to view.
21      if (!content_access('view', $field, NULL, $new_node)) {
22        continue;
23      }
24      $function = $field_types[$field['type']]['module'] . '_content_diff_values';
25      $function = function_exists($function) ? $function : 'content_content_diff_values';
26      $old_values = array();
27      $new_values = array();
28      if (isset($old_node->$field['field_name'])) {
29        $old_values = $function($old_node, $field, $old_node->$field['field_name']);
30      }
31      if (isset($new_node->$field['field_name'])) {
32        $new_values = $function($new_node, $field, $new_node->$field['field_name']);
33      }
34      if ($old_values || $new_values) {
35        $result[$field['field_name']] = array(
36          '#name' => $field['widget']['label'],
37          '#old' => $old_values,
38          '#new' => $new_values,
39          '#weight' => $field['widget']['weight'],
40          '#format' => array(
41            'show_header' => FALSE,
42          ),
43        );
44      }
45    }
46  }
47  return $result;
48}
49
50/**
51 * Default 'implementation' of hook_content_diff_values.
52 *
53 * Note that diff.module takes care of running check_plain on the output.
54 */
55function content_content_diff_values($node, $field, $items) {
56  $return = array();
57  foreach ($items as $item) {
58    foreach (explode("\n", $item['value']) as $i) {
59      $return[] = $i;
60    }
61  }
62  return $return;
63}
64
65if (module_exists('userreference')) {
66  /**
67   * Implementation of hook_content_diff_values.
68   */
69  function userreference_content_diff_values($node, $field, $items) {
70    static $titles = array();
71    // Gather ids.
72    $ids = array();
73    foreach ($items as $item) {
74      if ($item['uid'] && is_numeric($item['uid'])) {
75        $ids[] = $item['uid'];
76      }
77    }
78    // Fetch titles we don't know yet.
79    $queried_ids = array_diff($ids, array_keys($titles));
80    if ($queried_ids) {
81      $result = db_query('SELECT uid, name FROM {users} WHERE uid IN ('. db_placeholders($queried_ids) .')', $queried_ids);
82      while ($row = db_fetch_array($result)) {
83        $titles[$row['uid']] = $row['name'];
84      }
85    }
86    // Return result.
87    $return = array();
88    foreach ($items as $item) {
89      if ($item['uid'] && isset($titles[$item['uid']])) {
90        $return[] = $titles[$item['uid']];
91      }
92    }
93    return $return;
94  }
95}
96
97if (module_exists('nodereference')) {
98  /**
99   * Implementation of hook_content_diff_values.
100   */
101  function nodereference_content_diff_values($node, $field, $items) {
102    static $titles = array();
103    // Gather ids.
104    $ids = array();
105    foreach ($items as $item) {
106      if ($item['nid'] && is_numeric($item['nid'])) {
107        $ids[] = $item['nid'];
108      }
109    }
110    // Fetch titles we don't know yet.
111    $queried_ids = array_diff($ids, array_keys($titles));
112    if ($queried_ids) {
113      $result = db_query('SELECT nid, title FROM {node} WHERE nid IN ('. db_placeholders($queried_ids) .')', $queried_ids);
114      while ($row = db_fetch_array($result)) {
115        $titles[$row['nid']] = $row['title'];
116      }
117    }
118    // Return result.
119    $return = array();
120    foreach ($items as $item) {
121      if ($item['nid'] && isset($titles[$item['nid']])) {
122        $return[] = $titles[$item['nid']];
123      }
124    }
125    return $return;
126  }
127}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.