Projet

Général

Profil

Révision 13c3c9b4

Ajouté par Assos Assos il y a environ 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/advanced_forum/includes/style.inc
6 6
 * preprocess / theme functions.
7 7
 */
8 8

  
9
// STYLE API ****************************************************************/
10 9
/**
11 10
 * Returns the name of the forum style to use.
12 11
 */
......
14 13
  return variable_get('advanced_forum_style', 'silver_bells');
15 14
}
16 15

  
16
/**
17
 * Returns style.
18
 */
17 19
function advanced_forum_get_style($style) {
18 20
  ctools_include('plugins');
19 21
  return ctools_get_plugins('advanced_forum', 'styles', $style);
20 22
}
21 23

  
24
/**
25
 * Returns all styles.
26
 */
22 27
function advanced_forum_get_all_styles() {
23
  ctools_include('plugins') ;
28
  ctools_include('plugins');
24 29
  return ctools_get_plugins('advanced_forum', 'styles');
25 30
}
26 31

  
27 32
/**
28
 * Returns the path to the advanced forum style
33
 * Returns the path to the advanced forum style.
29 34
 */
30 35
function advanced_forum_path_to_style($requested_style = NULL) {
31 36
  // Set a static variable so this is cached after the first call.
......
37 42
  }
38 43

  
39 44
  if (empty($style_path)) {
40
    // Get the path information
45
    // Get the path information.
41 46
    $styles = advanced_forum_get_all_styles();
42 47
    foreach ($styles as $key => $style) {
43 48
      $style_paths[$key] = $style['path'];
......
47 52
}
48 53

  
49 54
/**
50
 * Starting at a given style, return paths of it and all ancestor styles
55
 * Starting at a given style, return paths of it and all ancestor styles.
51 56
 */
52 57
function advanced_forum_style_lineage($style = NULL) {
53 58
  static $lineages = array();
......
62 67
    // Get an array with information from all styles.
63 68
    $all_styles = advanced_forum_get_all_styles();
64 69

  
65
    // Fallback
66
    if (empty($all_styles[$style]))
70
    // Fallback.
71
    if (empty($all_styles[$style])) {
67 72
      $style = "silver_bells";
73
    }
68 74

  
69
    // Add the current style to the lineage first
75
    // Add the current style to the lineage first.
70 76
    $lineage[$style] = $all_styles[$style]['path'];
71 77

  
72 78
    // Check if there is an "extra style" listed. This allows you to grab the
......
100 106
}
101 107

  
102 108
/**
103
 * Starting at a given style, return path of template file
109
 * Starting at a given style, return path of template file.
104 110
 */
105 111
function advanced_forum_style_template_path($template_name, $style = NULL) {
106 112
  static $styles_files = array();
......
113 119

  
114 120
  $path = '';
115 121
  foreach ($lineage as $key => $path) {
116
    $template_path ="";
122
    $template_path = "";
117 123
  }
118
    return $path;
124

  
125
  return $path;
119 126
}
120 127

  
128
/**
129
 * Add basename of file.
130
 */
121 131
function advanced_forum_template_basename(&$file, $key, $extension) {
122 132
  $file->name = basename($file->uri, $extension);
123 133
}
124 134

  
135
/**
136
 * Find style template.
137
 */
125 138
function advanced_forum_find_style_templates($style = NULL) {
126
  // Get theme engine extension
139
  // Get theme engine extension.
127 140
  global $theme_engine;
128 141
  $extension = '.tpl.php';
129 142
  if (isset($theme_engine)) {
......
133 146
    }
134 147
  }
135 148

  
136
  // Most significant style template comes first in lineage array
149
  // Most significant style template comes first in lineage array.
137 150
  $lineage = array_reverse(advanced_forum_style_lineage($style), TRUE);
138 151

  
139 152
  $templates = array();
140 153

  
141
  // Loop through each style folder looking for templates
154
  // Loop through each style folder looking for templates.
142 155
  foreach ($lineage as $key => $path) {
143 156
    $styles_files = file_scan_directory($path, '/' . str_replace('.', '\.', $extension) . '$/', array('key' => 'filename'));
144
    // Fix name - file_scan_directory returns template.tpl as name
145
    //array_walk($styles_files, 'advanced_forum_template_basename', $extension);
146 157
    foreach ($styles_files as $file) {
147 158
      $file->name = basename($file->uri, $extension);
148 159
      $theme_file = $file->name;
149 160
      $theme_path = advanced_forum_path_to_theme();
150 161

  
151
      // Remove style name from file name
162
      // Remove style name from file name.
152 163
      $theme_base_file = str_replace(".$key.", "-", $file->name);
153 164

  
154 165
      // Transform - in filenames to _ to match function naming scheme
155
      // and create proper hook name
166
      // and create proper hook name.
156 167
      $hook = strtr($theme_base_file, '-', '_');
157 168

  
158 169
      // Check for user theme template override
......
164 175
      elseif (file_exists($theme_path . "/" . $theme_base_file . $extension)) {
165 176
        $theme_file = $theme_base_file;
166 177
      }
167
      // 3. check for advanced_forum/styles/<style>/... template
178
      // 3. check for advanced_forum/styles/<style>/... template.
168 179
      else {
169 180
        $theme_path = dirname($file->uri);
170 181
      }
......
179 190
}
180 191

  
181 192
/**
182
 * Load any .inc files related to the style so that preprocess
183
 * functions can run as appropriate.
193
 * Load any .inc files related to the style so that preprocess functions can run as appropriate.
184 194
 */
185 195
function advanced_forum_load_style_includes($style = NULL) {
186 196
  $lineage = advanced_forum_style_lineage($style);
187 197
  foreach ($lineage as $key => $path) {
188 198
    if (file_exists("$path/$key.inc")) {
189
      require_once("$path/$key.inc");
199
      require_once "$path/$key.inc";
190 200
    }
191 201
  }
192 202
}
193 203

  
194 204
/**
195
 * Get the info for a style, using an additive notation to
196
 * include all items from the parent lineage.
205
 * Get the info for a style, using an additive notation to include all items from the parent lineage.
197 206
 */
198 207
function advanced_forum_style_info($style = NULL) {
199 208
  static $info = array();
......
206 215
    $info[$style] = array();
207 216
    $lineage = advanced_forum_style_lineage();
208 217
    foreach ($lineage as $key => $dir) {
209
      // using the + operator is additive but will not overwrite.
218
      // Using the + operator is additive but will not overwrite.
210 219
      // $lineage comes out as the actual style with each
211 220
      // successive style after it, so simply adding the arrays
212 221
      // together means that all info will be combined and keys
......
219 228
  return $info[$style];
220 229
}
221 230

  
231
/**
232
 * Returns whether forum is styled.
233
 */
222 234
function advanced_forum_is_styled($content, $teaser = FALSE, $type = 'node') {
223
  // This is the ID of the topic starting node
235
  // This is the ID of the topic starting node.
224 236
  static $master_topic_id;
225 237

  
226 238
  // Give other modules a first crack at making the decision. To keep this
......
246 258
          $topic_id = $master_topic_id;
247 259
        }
248 260
        break;
249
      }
250 261
    }
262
  }
251 263

  
252 264
  if ($topic_id > 0) {
253 265
    // If we have a positive number for the topic ID, then this item is styled.
......
267 279

  
268 280
}
269 281

  
282
/**
283
 * Returns whether node is styled.
284
 */
270 285
function advanced_forum_node_is_styled($node, $teaser = FALSE) {
271
  // Get the list of types that should have the style applied
286
  // Get the list of types that should have the style applied.
272 287
  $styled_node_types = variable_get('advanced_forum_styled_node_types', array('forum'));
273 288
  // If this type is in the list of types that should be styled...
274 289
  if (in_array($node->type, $styled_node_types)) {
......
295 310
  }
296 311
}
297 312

  
313
/**
314
 * Returns whether comment is styled.
315
 */
298 316
function advanced_forum_comment_is_styled($comment, $master_topic_id) {
299 317
  if (isset($master_topic_id) && ($comment->nid == $master_topic_id)) {
300 318
    // This comment is on a node we already know is styled, or a previous
......
315 333
    return $comment->nid;
316 334
  }
317 335

  
318
  // Comment doesn't pass any styling test
336
  // Comment doesn't pass any styling test.
319 337
  return -1;
320 338
}
321 339

  
340
/**
341
 * Returns whether forum is tagged.
342
 */
322 343
function advanced_forum_is_forum_tagged($node, $preview = FALSE) {
323 344
  // Is this a forum node at all?
324 345
  if (empty($node->taxonomy_forums)) {
......
326 347
  }
327 348
  $vid = variable_get('forum_nav_vocabulary');
328 349

  
329
  // Check for language used
350
  // Check for language used.
330 351
  if (empty($node->taxonomy_forums[$node->language])) {
331 352
    $langcode = LANGUAGE_NONE;
332 353
  }
......
335 356
  }
336 357

  
337 358
  if ($preview) {
338
     foreach ($node->taxonomy_forums[$langcode] as $tforum) {
359
    foreach ($node->taxonomy_forums[$langcode] as $tforum) {
339 360
      if ($tforum['taxonomy_term']->vid == $vid) {
340 361
        return TRUE;
341 362
      }
342 363
    }
343 364
  }
344 365
  else {
345
    // Get a list of the terms attached to this node
366
    // Get a list of the terms attached to this node.
346 367
    $terms = $node->taxonomy_forums[$langcode];
347 368
    if (count($terms) > 0) {
348 369
      return TRUE;
......
370 391
}
371 392

  
372 393
/**
373
 * Manipulate the template suggestions to add in one for each style as well
374
 * as the default.
394
 * Manipulate the template suggestions to add in one for each style as well as the default.
375 395
 */
376 396
function advanced_forum_add_template_suggestions($template, &$variables) {
377
  // adjust template name
397
  // Adjust template name.
378 398
  $template = strtr($template, '-', '_');
379 399
  if (strpos($template, 'advanced_forum') === FALSE) {
380 400
    $template = "advanced_forum_" . $template;
381 401
  }
382
  // Set AF template as most significant suggestion
402
  // Set AF template as most significant suggestion.
383 403
  $variables['theme_hook_suggestion'] = $template;
384 404
  $variables['theme_hook_suggestions'][] = $template;
385 405
  return;
......
387 407

  
388 408
/**
389 409
 * Adds extra files needed for styling.
410
 *
390 411
 * This is currently just CSS files but was made generic to allow adding
391 412
 * javascript in the future.
392 413
 */
......
411 432
        // For each style from the current style on up through each parent
412 433
        // style, look for the style specific CSS file first in the active
413 434
        // theme and then in the style directory.
414
        foreach ($lineage AS $key => $path) {
435
        foreach ($lineage as $key => $path) {
415 436
          $css_file = "advanced-forum.$key.$css_type";
416 437
          if (file_exists("$theme_path/$css_file")) {
417 438
            // If the style specific file is in the theme, use that.
......
429 450
  }
430 451
}
431 452

  
432
// CTOOLS INTEGRATION FOR STYLES ********************************************/
433

  
453
/**
454
 * Ctools integration for styles.
455
 */
434 456
function advanced_forum_ctools_plugin_type() {
435 457
  return array(
436 458
    'styles' => array(

Formats disponibles : Unified diff