url.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace Elementor;
  3. use Elementor\Modules\DynamicTags\Module as TagsModule;
  4. if ( ! defined( 'ABSPATH' ) ) {
  5. exit; // Exit if accessed directly.
  6. }
  7. /**
  8. * Elementor URL control.
  9. *
  10. * A base control for creating url control. Displays a URL input with the
  11. * ability to set the target of the link to `_blank` to open in a new tab.
  12. *
  13. * @since 1.0.0
  14. */
  15. class Control_URL extends Control_Base_Multiple {
  16. /**
  17. * Get url control type.
  18. *
  19. * Retrieve the control type, in this case `url`.
  20. *
  21. * @since 1.0.0
  22. * @access public
  23. *
  24. * @return string Control type.
  25. */
  26. public function get_type() {
  27. return 'url';
  28. }
  29. /**
  30. * Get url control default values.
  31. *
  32. * Retrieve the default value of the url control. Used to return the default
  33. * values while initializing the url control.
  34. *
  35. * @since 1.0.0
  36. * @access public
  37. *
  38. * @return array Control default value.
  39. */
  40. public function get_default_value() {
  41. return [
  42. 'url' => '',
  43. 'is_external' => '',
  44. 'nofollow' => '',
  45. ];
  46. }
  47. /**
  48. * Get url control default settings.
  49. *
  50. * Retrieve the default settings of the url control. Used to return the default
  51. * settings while initializing the url control.
  52. *
  53. * @since 1.0.0
  54. * @access protected
  55. *
  56. * @return array Control default settings.
  57. */
  58. protected function get_default_settings() {
  59. return [
  60. 'label_block' => true,
  61. 'show_external' => true,
  62. 'placeholder' => __( 'Paste URL or type', 'elementor' ),
  63. 'dynamic' => [
  64. 'categories' => [ TagsModule::URL_CATEGORY ],
  65. 'property' => 'url',
  66. ],
  67. ];
  68. }
  69. /**
  70. * Render url control output in the editor.
  71. *
  72. * Used to generate the control HTML in the editor using Underscore JS
  73. * template. The variables for the class are available using `data` JS
  74. * object.
  75. *
  76. * @since 1.0.0
  77. * @access public
  78. */
  79. public function content_template() {
  80. $control_uid = $this->get_control_uid();
  81. $more_input_control_uid = $this->get_control_uid( 'more-input' );
  82. $is_external_control_uid = $this->get_control_uid( 'is_external' );
  83. $nofollow_control_uid = $this->get_control_uid( 'nofollow' );
  84. ?>
  85. <div class="elementor-control-field elementor-control-url-external-{{{ data.show_external ? 'show' : 'hide' }}}">
  86. <label for="<?php echo $control_uid; ?>" class="elementor-control-title">{{{ data.label }}}</label>
  87. <div class="elementor-control-input-wrapper">
  88. <i class="elementor-control-url-autocomplete-spinner fa fa-spin fa-circle-o-notch" aria-hidden="true"></i>
  89. <input id="<?php echo $control_uid; ?>" class="elementor-control-tag-area elementor-input" data-setting="url" placeholder="{{ data.placeholder }}" />
  90. <input id="_ajax_linking_nonce" type="hidden" value="<?php echo wp_create_nonce( 'internal-linking' ); ?>" />
  91. <label for="<?php echo $more_input_control_uid; ?>" class="elementor-control-url-more tooltip-target" data-tooltip="<?php echo __( 'Link Options', 'elementor' ); ?>">
  92. <i class="fa fa-cog" aria-hidden="true"></i>
  93. </label>
  94. <input id="<?php echo $more_input_control_uid; ?>" type="checkbox" class="elementor-control-url-more-input">
  95. <div class="elementor-control-url-more-options">
  96. <div class="elementor-control-url-option">
  97. <input id="<?php echo $is_external_control_uid; ?>" type="checkbox" class="elementor-control-url-option-input" data-setting="is_external">
  98. <label for="<?php echo $is_external_control_uid; ?>"><?php echo __( 'Open in new window', 'elementor' ); ?></label>
  99. </div>
  100. <div class="elementor-control-url-option">
  101. <input id="<?php echo $nofollow_control_uid; ?>" type="checkbox" class="elementor-control-url-option-input" data-setting="nofollow">
  102. <label for="<?php echo $nofollow_control_uid; ?>"><?php echo __( 'Add nofollow', 'elementor' ); ?></label>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. <# if ( data.description ) { #>
  108. <div class="elementor-control-field-description">{{{ data.description }}}</div>
  109. <# } #>
  110. <?php
  111. }
  112. }