Projet

Général

Profil

Révision 7e72b748

Ajouté par Assos Assos il y a plus de 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ctools/includes/plugins.inc
2 2

  
3 3
/**
4 4
 * @file
5
 *
6 5
 * Contains routines to organize and load plugins. It allows a special
7 6
 * variation of the hook system so that plugins can be kept in separate
8 7
 * .inc files, and can be either loaded all at once or loaded only when
......
70 69
      if (isset($info['version'])) {
71 70
        $version = $info['version'];
72 71
      }
73
      else if (isset($info['api'])) {
72
      elseif (isset($info['api'])) {
74 73
        $version = $info['api'];
75 74
      }
76 75

  
......
99 98
        }
100 99

  
101 100
        // Only process if version is between minimum and current, inclusive.
102
      if (version_compare($info['version'], $minimum_version, '>=') && version_compare($info['version'], $current_version, '<=')) {
101
        if (version_compare($info['version'], $minimum_version, '>=') && version_compare($info['version'], $current_version, '<=')) {
103 102
          if (!isset($info['path'])) {
104 103
            $info['path'] = '';
105 104
          }
......
151 150
      if (isset($plugin_info["$api file"])) {
152 151
        $file = $plugin_info["$api file"];
153 152
      }
154
      else if (isset($plugin_info['file'])) {
153
      elseif (isset($plugin_info['file'])) {
155 154
        $file = $plugin_info['file'];
156 155
      }
157 156
      else {
......
161 160
      if (file_exists(DRUPAL_ROOT . "/$plugin_info[path]/$file")) {
162 161
        require_once DRUPAL_ROOT . "/$plugin_info[path]/$file";
163 162
      }
164
      else if (file_exists(DRUPAL_ROOT . "/$file")) {
163
      elseif (file_exists(DRUPAL_ROOT . "/$file")) {
165 164
        require_once DRUPAL_ROOT . "/$file";
166 165
      }
167 166
      $already_done[$owner][$api][$module] = TRUE;
......
184 183
  if (function_exists($function = $owner . '_' . $api . '_hook_name')) {
185 184
    $hook = $function();
186 185
  }
187
  else if (function_exists($function = $owner . '_ctools_plugin_api_hook_name')) {
186
  elseif (function_exists($function = $owner . '_ctools_plugin_api_hook_name')) {
188 187
    $hook = $function();
189 188
  }
190 189

  
......
225 224
  $info = ctools_plugin_get_plugin_type_info();
226 225

  
227 226
  if (!isset($info[$module][$type])) {
228
    // If we don't find the plugin we attempt a cache rebuild before bailing out
227
    // If we don't find the plugin we attempt a cache rebuild before bailing out.
229 228
    $info = ctools_plugin_get_plugin_type_info(TRUE);
230 229
    // Bail out noisily if an invalid module/type combination is requested.
231 230
    if (!isset($info[$module][$type])) {
......
258 257

  
259 258
    if (!empty($cache->data)) {
260 259
      // Cache load succeeded so use the cached plugin list.
261
      $plugins[$module][$type]   = $cache->data;
260
      $plugins[$module][$type] = $cache->data;
262 261
      // Set $setup to true so we know things where loaded.
263
      $setup[$module][$type]     = TRUE;
262
      $setup[$module][$type] = TRUE;
264 263
    }
265 264
    else {
266 265
      // Cache load failed so store that we need to build and write the cache.
......
299 298
    }
300 299
  }
301 300

  
302

  
303 301
  // If we were told earlier that this is cacheable and the cache was empty,
304 302
  // give something back.
305 303
  if ($build_cache) {
......
313 311
    return array_filter($plugins[$module][$type]);
314 312
  }
315 313

  
316
  // Check to see if we need to look for the file
314
  // Check to see if we need to look for the file.
317 315
  if (!array_key_exists($id, $plugins[$module][$type])) {
318 316
    // If we can have child plugins, check to see if the plugin name is in the
319 317
    // format of parent:child and break it up if it is.
......
419 417
/**
420 418
 * Load plugins from a directory.
421 419
 *
422
 * @param $info
420
 * @param array $info
423 421
 *   The plugin info as returned by ctools_plugin_get_info()
424
 * @param $file
422
 * @param string $filename
425 423
 *   The file to load if we're looking for just one particular plugin.
426 424
 *
427
 * @return
428
 *   An array of information created for this plugin.
425
 * @return array
426
 *   A (possibly empty) array of information created for this plugin.
429 427
 */
430 428
function ctools_plugin_load_includes($info, $filename = NULL) {
431 429
  // Keep a static array so we don't hit file_scan_directory more than necessary.
432 430
  $all_files = &drupal_static(__FUNCTION__, array());
433 431

  
434
  // store static of plugin arrays for reference because they can't be reincluded.
432
  // Store static of plugin arrays for reference because they can't be
433
  // reincluded, so there is no point in using drupal_static().
435 434
  static $plugin_arrays = array();
436 435

  
437 436
  if (!isset($all_files[$info['module']][$info['type']])) {
......
466 465
    }
467 466
    foreach ($files as $file) {
468 467
      if (!empty($info['info file'])) {
469
        // Parse a .info file
468
        // Parse a .info file.
470 469
        $result = ctools_plugin_process_info($info, $module, $file);
471 470
      }
472 471
      else {
473 472
        // Parse a hook.
474
        $plugin = NULL; // ensure that we don't have something leftover from earlier.
473
        // Ensure that we don't have something leftover from earlier.
474
        $plugin = NULL;
475 475

  
476 476
        if (isset($plugin_arrays[$file->uri])) {
477 477
          $identifier = $plugin_arrays[$file->uri];
478 478
        }
479 479
        else {
480

  
481 480
          include_once DRUPAL_ROOT . '/' . $file->uri;
482 481
          // .inc files have a special format for the hook identifier.
483 482
          // For example, 'foo.inc' in the module 'mogul' using the plugin
484
          // whose hook is named 'borg_type' should have a function named (deep breath)
485
          // mogul_foo_borg_type()
486

  
483
          // whose hook is named 'borg_type' should have a function named
484
          // (deep breath) mogul_foo_borg_type().
487 485
          // If, however, the .inc file set the quasi-global $plugin array, we
488 486
          // can use that and not even call a function. Set the $identifier
489 487
          // appropriately and ctools_plugin_process() will handle it.
......
496 494
          }
497 495
        }
498 496

  
499
        $result = ctools_plugin_process($info, $module, $identifier, dirname($file->uri), basename($file->uri), $file->name);
497
        $result = ctools_plugin_process($info, $module, $identifier,
498
          dirname($file->uri), basename($file->uri), $file->name);
500 499
      }
501 500
      if (is_array($result)) {
502 501
        $plugins = array_merge($plugins, $result);
......
516 515
 * @param $info
517 516
 *   The $info array for the plugin as returned by ctools_plugin_get_info().
518 517
 *
519
 * @return array $directories
518
 * @return array
520 519
 *   An array of directories to search.
521 520
 */
522 521
function ctools_plugin_get_directories($info) {
......
542 541
}
543 542

  
544 543
/**
545
 * Helper function to build a ctools-friendly list of themes capable of
546
 * providing plugins.
544
 * Helper to build a ctools-friendly list of themes capable of providing plugins.
547 545
 *
548
 * @return array $themes
546
 * @return array
549 547
 *   A list of themes that can act as plugin providers, sorted parent-first with
550 548
 *   the active theme placed last.
551 549
 */
552 550
function _ctools_list_themes() {
551
  // @TODO: Use drupal_static() here?
553 552
  static $themes;
554 553
  if (is_null($themes)) {
555 554
    $current = variable_get('theme_default', FALSE);
556 555
    $themes = $active = array();
557 556
    $all_themes = list_themes();
558 557
    foreach ($all_themes as $name => $theme) {
559
      // Only search from active themes
558
      // Only search from active themes.
560 559
      if (empty($theme->status) && $theme->name != $current) {
561 560
        continue;
562 561
      }
......
567 566
      }
568 567
    }
569 568

  
570
    // Construct a parent-first list of all themes
569
    // Construct a parent-first list of all themes.
571 570
    foreach ($active as $name => $theme) {
572 571
      $base_themes = isset($theme->base_themes) ? $theme->base_themes : array();
573 572
      $themes = array_merge($themes, $base_themes, array($name => $theme->info['name']));
574 573
    }
575
    // Put the actual theme info objects into the array
574
    // Put the actual theme info objects into the array.
576 575
    foreach (array_keys($themes) as $name) {
577 576
      if (isset($all_themes[$name])) {
578 577
        $themes[$name] = $all_themes[$name];
579 578
      }
580 579
    }
581 580

  
582
    // Make sure the current default theme always gets the last word
581
    // Make sure the current default theme always gets the last word.
583 582
    if ($current_key = array_search($current, array_keys($themes))) {
584 583
      $themes += array_splice($themes, $current_key, 1);
585 584
    }
......
587 586
  return $themes;
588 587
}
589 588

  
590

  
591 589
/**
592 590
 * Find all the base themes for the specified theme.
593 591
 *
......
603 601
 *   The name of the theme whose base we are looking for.
604 602
 * @param $used_keys
605 603
 *   A recursion parameter preventing endless loops.
606
 * @return
604
 *
605
 * @return array
607 606
 *   Returns an array of all of the theme's ancestors; the first element's value
608
 *   will be NULL if an error occurred.
607
 *   will be NULL if an error occurred. (Note: this is NOT $arr[0]).
609 608
 */
610 609
function ctools_find_base_themes($themes, $key, $used_keys = array()) {
611 610
  $base_key = $themes[$key]->info['base theme'];
......
633 632
  return $current_base_theme;
634 633
}
635 634

  
636

  
637 635
/**
638 636
 * Load plugin info for the provided hook; this is handled separately from
639 637
 * plugins from files.
......
658 656
/**
659 657
 * Process a single hook implementation of a ctools plugin.
660 658
 *
661
 * @param $info
659
 * @param array $info
662 660
 *   The $info array about the plugin as returned by ctools_plugin_get_info()
663
 * @param $module
661
 * @param string $module
664 662
 *   The module that implements the plugin being processed.
665
 * @param $identifier
666
 *   The plugin identifier, which is used to create the name of the hook
667
 *   function being called.
668
 * @param $path
663
 * @param string|array $identifier
664
 *   Used to create the base setting of return value. If:
665
 *    - $identifier is a string, a hook name is created from this and the 'hook'
666
 *      key of the $info array, and the return value of that hook function is
667
 *      used. The hook is called like this: $identifier_$hook($info);
668
 *    - $identifier is an array, this array is used directly.
669
 * @param string $path
669 670
 *   The path where files utilized by this plugin will be found.
670
 * @param $file
671
 * @param string $file
671 672
 *   The file that was loaded for this plugin, if it exists.
672
 * @param $base
673
 * @param string $base
673 674
 *   The base plugin name to use. If a file was loaded for the plugin, this
674 675
 *   is the plugin to assume must be present. This is used to automatically
675 676
 *   translate the array to make the syntax more friendly to plugin
676 677
 *   implementors.
678
 *
679
 * @return null|array
680
 *   NULL on failure, otherwise an array containing the results keyed by name.
677 681
 */
678 682
function ctools_plugin_process($info, $module, $identifier, $path, $file = NULL, $base = NULL) {
679 683
  if (is_array($identifier)) {
......
741 745
  return $result;
742 746
}
743 747

  
744

  
745 748
/**
746 749
 * Process an info file for plugin information, rather than a hook.
750
 *
751
 * @param array $info
752
 *   The $info array about the plugin as returned by ctools_plugin_get_info()
753
 * @param string $module
754
 *   The module that implements the plugin being processed.
755
 * @param object $file
756
 *   An object containing 'uri' and 'name' properties. 'uri' is the name of the
757
 *   'info' file to process. 'name' is the plugin key-name.
758
 *
759
 * @return null|array
760
 *   NULL on failure, otherwise an array containing the results keyed by name.
747 761
 */
748 762
function ctools_plugin_process_info($info, $module, $file) {
749 763
  $result = drupal_parse_info_file($file->uri);
......
770 784
 * @param $function_name
771 785
 *   The identifier of the function. For example, 'settings form'.
772 786
 *
773
 * @return
787
 * @return string
774 788
 *   The actual name of the function to call, or NULL if the function
775 789
 *   does not exist.
776 790
 */
......
787 801
  }
788 802

  
789 803
  if (!isset($plugin_definition[$function_name])) {
790
    return;
804
    return NULL;
791 805
  }
792 806

  
793 807
  if (is_array($plugin_definition[$function_name]) && isset($plugin_definition[$function_name]['function'])) {
......
822 836
 * @param $function_name
823 837
 *   The identifier of the function. For example, 'settings form'.
824 838
 *
825
 * @return
839
 * @return string
826 840
 *   The actual name of the function to call, or NULL if the function
827 841
 *   does not exist.
828 842
 */
......
840 854
 * @param $class_name
841 855
 *   The identifier of the class. For example, 'handler'.
842 856
 *
843
 * @return
857
 * @return string
844 858
 *   The actual name of the class to call, or NULL if the class does not exist.
845 859
 */
846 860
function ctools_plugin_get_class($plugin_definition, $class_name) {
......
859 873
  if (!isset($plugin_definition[$class_name])) {
860 874
    return;
861 875
  }
862
  else if (is_string($plugin_definition[$class_name])) {
876
  elseif (is_string($plugin_definition[$class_name])) {
863 877
    // Plugin uses the string form shorthand.
864 878
    $return = $plugin_definition[$class_name];
865 879
  }
866
  else if (isset($plugin_definition[$class_name]['class'])) {
880
  elseif (isset($plugin_definition[$class_name]['class'])) {
867 881
    // Plugin uses the verbose array form.
868 882
    $return = $plugin_definition[$class_name]['class'];
869 883
  }
......
885 899
 * @param $class_name
886 900
 *   The identifier of the class. For example, 'handler'.
887 901
 *
888
 * @return
902
 * @return string
889 903
 *   The actual name of the class to call, or NULL if the class does not exist.
890 904
 */
891 905
function ctools_plugin_load_class($module, $type, $id, $class_name) {

Formats disponibles : Unified diff