/[drupal]/contributions/modules/reptag/reptag_process.inc
ViewVC logotype

Contents of /contributions/modules/reptag/reptag_process.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.26 - (show annotations) (download) (as text)
Wed Jun 4 12:21:06 2008 UTC (17 months, 3 weeks ago) by profix898
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.25: +67 -202 lines
File MIME type: text/x-php
- task: initial version for Drupal 6
1 <?php
2 // $Id: reptag_process.inc,v 1.23.2.11 2007/07/25 16:14:31 profix898 Exp $
3
4 require_once(drupal_get_path('module', 'reptag') .'/reptag_helper.inc');
5 require_once(drupal_get_path('module', 'reptag') .'/reptag_module.inc');
6
7 /**
8 * Simple (wrapper) API function for text replacements
9 * (You can use reptag_replace() to process a piece of text instead
10 * of calling reptag_process() directly)
11 *
12 * @param $text
13 * The text/content to be processed.
14 * @param $procall
15 * By default only static tags are replaced using reptag_replace(),
16 * set $procall = TRUE to use all tags (static + dynamic) instead.
17 */
18 function reptag_replace($text, $procall = FALSE) {
19 global $user;
20
21 $content = new stdClass();
22 $content->uid = $user->uid;
23 $content->text = $text;
24 reptag_process($content, array('text'), $procall ? REPTAG_PROCALL : REPTAG_PROCSTATIC);
25
26 return $content->text;
27 }
28
29 /**
30 * Perform the actual reptag processing
31 * (This function does all the filter/replacement stuff)
32 *
33 * @param $content
34 * An object containing the content (and its context) to be processed.
35 * @param $fields
36 * An array containing all fields (or field pathes) of $content to be processed
37 * e.g. 'fieldA' for $content->fieldA
38 * 'fieldA/fieldB' for $content->fieldA->fieldB
39 * 'fieldA/fieldB/fieldC' for $content->fieldA->fieldB-fieldC etc.
40 * (this also works when $content is not an object but an array)
41 * @param $proc
42 * An integer to set the processing mode (e.g. REPTAG_PROCALL, ...).
43 * @param $modules
44 * An array containing the names of all modules to be used
45 * e.g. array('system.tags', 'node.tags')
46 * @param $lang
47 * The language code (e.g. 'de') of the replacements to use.
48 * Omit this parameter to use the language of the current page request (auto-negotiate)
49 *
50 * See DEVELOPER.TXT for detailed information
51 */
52 function reptag_process(&$content, $fields = array('text'), $proc = REPTAG_PROCALL, $modules = NULL, $lang = NULL) {
53 // Return immediately on empty $fields array
54 if (empty($fields)) {
55 return;
56 }
57
58 // Set default user if no uid is provided
59 if (!isset($content->uid)) {
60 $content->uid = 0; // anonymous user
61 }
62
63 // Get roles associated with current node
64 $content_roles = _reptag_user_get_roles($content->uid);
65
66 // Load module tags
67 $reptags = _reptag_module_tags($proc, $content_roles, $content, $modules);
68 if ($proc == REPTAG_PROCDYNAMIC && empty($reptags)) {
69 return;
70 }
71
72 // Load exclude tags
73 $exclude_tags = array();
74 foreach ($content_roles as $rid) {
75 $rid_tags = _reptag_exclude_loadtags($rid);
76 $exclude_tags = array_filter(array_merge($exclude_tags, $rid_tags));
77 }
78
79 // Filter exclude_tags from reptags
80 $reptags = _reptag_filter_exclude($reptags, $exclude_tags);
81
82 // Load side-wide and user tags from tables
83 if ($proc != REPTAG_PROCDYNAMIC) {
84
85 $iid = array(0, $content->uid);
86 $reptag_table = _reptag_table_load($iid, REPTAG_LOADTAG_DEFAULT, $lang);
87
88 // Load tags of default language and merge in
89 if (variable_get('reptag_locale_enable', 0)
90 && (variable_get('reptag_locale_mode', REPTAG_LOCALE_STRICT) == REPTAG_LOCALE_FALLBACK)
91 && (_reptag_language() != language_default('language'))) {
92 $default_tags = _reptag_table_load($iid, REPTAG_LOADTAG_DEFAULT, language_default('language'));
93 $reptag_table = array_merge($default_tags, $reptag_table);
94 }
95
96 // Remove all html tags for plain text roles
97 $plainrep_roles = unserialize(variable_get('reptag_plainrep_roles', serialize(array())));
98 if (array_intersect($plainrep_roles, $content_roles)) {
99 foreach ($reptag_table as $tag => $repl) {
100 $reptag_table[$tag] = check_plain(strip_tags($repl));
101 }
102 }
103
104 // Filter exclude_tags from reptag_table
105 foreach ($exclude_tags as $key) {
106 $key = '#\\'. strtoupper(substr($key, 0, -1)) .'\$#si';
107 unset($reptag_table[$key]);
108 }
109
110 }
111
112 // Debug
113 if (variable_get('reptag_debug', 0)) {
114 _reptag_debug($fields, 'Fields');
115 _reptag_debug($reptags, 'Module RepTags');
116 _reptag_debug($reptag_table, 'Table RepTags');
117 _reptag_debug($content, 'Content');
118 }
119
120 // If 'body' field is included add 'teaser' field also
121 // empty fields will be skipped below
122 if (in_array('content/body/#value', $fields) || in_array('body', $fields)) {
123 $fields[] = 'teaser';
124 }
125
126 // Iterate over all $fields
127 foreach ($fields as $field) {
128
129 // Point to the text/string to be processed
130 $text =& _reptag_content_field($content, $field);
131 // Only continue with a valid (non-empty) string
132 if (!is_string($text) || empty($text)) {
133 continue;
134 }
135
136 // Process table tags
137 if ($proc != REPTAG_PROCDYNAMIC) {
138 $text = preg_replace(array_keys($reptag_table), array_values($reptag_table), $text);
139 }
140
141 // Process module tags
142 foreach ($reptags as $module => $tags) {
143 $result = _reptag_module_invoke($module, 'process', $text, $tags, $content);
144 $text = $result ? $result : preg_replace(array_keys($tags), array_values($tags), $text);
145 }
146
147 }
148 }
149
150 /**
151 * Function _reptag_filter_exclude().
152 */
153 function _reptag_filter_exclude($reptags, $exclude_tags) {
154 foreach ($reptags as $module => $tags) {
155 $matches = array_intersect(array_keys($tags), array_values($exclude_tags));
156 foreach ($matches as $key) {
157 unset($reptags[$module][$key]);
158 }
159 }
160
161 return $reptags;
162 }

  ViewVC Help
Powered by ViewVC 1.1.2