profile.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @file
  4. * Linkit Profile class.
  5. */
  6. /**
  7. * Linkit Profile class implementation.
  8. */
  9. class LinkitProfile {
  10. /**
  11. * The profile data (settings).
  12. *
  13. * @var array
  14. */
  15. public $data;
  16. /**
  17. * All enabled attributes for this profile.
  18. *
  19. * @var array
  20. */
  21. protected $enabled_attribute_plugins;
  22. /**
  23. * All enabled search plugins for this profile.
  24. *
  25. * @var array
  26. */
  27. protected $enabled_search_plugins;
  28. /**
  29. * Set all enabled attribure plugins.
  30. */
  31. public function setEnabledAttributePlugins() {
  32. foreach ($this->data['attribute_plugins'] as $attribute_name => $attribute) {
  33. if ($attribute['enabled']) {
  34. // Load the attribute plugin.
  35. $attribute_plugin = linkit_attribute_plugin_load($attribute_name);
  36. // Call the callback to get the FAPI element.
  37. if (isset($attribute_plugin['callback']) && function_exists($attribute_plugin['callback'])) {
  38. $attribute_html = $attribute_plugin['callback']($attribute_plugin, $attribute);
  39. // Add Linkit specific class, this is used by the editor JS scripts.
  40. $attribute_html['#attributes']['class'][] = 'linkit-attribute';
  41. $this->enabled_attribute_plugins[$attribute_name] = $attribute_html;
  42. }
  43. }
  44. }
  45. }
  46. /**
  47. * Set all enabled search plugins.
  48. */
  49. public function setEnabledsearchPlugins() {
  50. // Sort plugins by weight.
  51. uasort($this->data['search_plugins'], 'linkit_sort_plugins_by_weight');
  52. foreach ($this->data['search_plugins'] as $plugin_name => $plugin) {
  53. if ($plugin['enabled']) {
  54. // Load plugin definition.
  55. $plugin_definition = linkit_search_plugin_load($plugin_name);
  56. // Get a Linkit search plugin object.
  57. $search_plugin = LinkitSearchPlugin::factory($plugin_definition, $this);
  58. // Only register none broken plugins.
  59. if ($search_plugin->broken() !== TRUE) {
  60. $this->enabled_search_plugins[$plugin_name] = $search_plugin;
  61. }
  62. }
  63. }
  64. }
  65. /**
  66. * Construct an array with all the enabled attribute plugins for this profile.
  67. *
  68. * @return
  69. * An array with all enabled attribute plugins for this profile.
  70. */
  71. public function getEnabledAttributePlugins() {
  72. if (!isset($this->enabled_attribute_plugins)) {
  73. $this->setEnabledAttributePlugins();
  74. }
  75. return $this->enabled_attribute_plugins;
  76. }
  77. /**
  78. * Construct an array with all enabled search plugins for this profile.
  79. *
  80. * @return
  81. * An array with all enabled search plugins for this profile.
  82. */
  83. public function getEnabledsearchPlugins() {
  84. if (!isset($this->enabled_search_plugins)) {
  85. $this->setEnabledsearchPlugins();
  86. }
  87. return $this->enabled_search_plugins;
  88. }
  89. }