You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3 KiB

  1. <?php namespace Sensory5\Shortcode;
  2. use App;
  3. use Str;
  4. use Html;
  5. use Event;
  6. use System\Classes\PluginBase;
  7. use Illuminate\Foundation\AliasLoader;
  8. use Sensory5\Shortcode\Models\Settings;
  9. /**
  10. * Shortcode Plugin Information File
  11. */
  12. class Plugin extends PluginBase
  13. {
  14. /**
  15. * Returns information about this plugin.
  16. *
  17. * @return array
  18. */
  19. public function pluginDetails()
  20. {
  21. return [
  22. 'name' => 'Shortcode',
  23. 'description' => 'Shortcode integration for OctoberCMS.',
  24. 'author' => 'Sensory 5',
  25. 'icon' => 'icon-code'
  26. ];
  27. }
  28. /**
  29. * Register service provider, Twig extensions, and alias facade.
  30. */
  31. public function boot()
  32. {
  33. // Service provider
  34. App::register('\Sensory5\Shortcode\Classes\ServiceProvider');
  35. // Register alias
  36. $alias = AliasLoader::getInstance();
  37. $alias->alias('Shortcode', '\Sensory5\Shortcode\Classes\Facade');
  38. // Enable shortcodes on all pages if requested
  39. if (Settings::get('enable_on_render', false))
  40. {
  41. Event::listen('cms.page.postprocess', function($controller, $url, $page, $dataHolder) {
  42. // Only parse strings, so that we don't interrupt
  43. // ajax responses that are in object or array form
  44. if (is_string($dataHolder->content))
  45. {
  46. $dataHolder->content = \Shortcode::parse($dataHolder->content);
  47. }
  48. });
  49. }
  50. }
  51. /**
  52. * Register twig filters
  53. */
  54. public function registerMarkupTags()
  55. {
  56. return [
  57. 'filters' => [ 'shortcode' => ['\Shortcode', 'parse'] ],
  58. 'functions' => ['shortcode' => ['\Shortcode', 'parse'] ]
  59. ];
  60. }
  61. /**
  62. * Register backend settings
  63. */
  64. public function registerSettings()
  65. {
  66. return [
  67. 'settings' => [
  68. 'label' => 'Shortcode Settings',
  69. 'description' => 'Manage shortcode settings',
  70. 'category' => 'Shortcodes',
  71. 'icon' => 'icon-code',
  72. 'class' => 'Sensory5\Shortcode\Models\Settings',
  73. 'order' => 600,
  74. 'keywords' => 'shortcode shortcodes'
  75. ]
  76. ];
  77. }
  78. }