PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/plugins/wordpress-seo/vendor/yoast/license-manager/class-product.php

https://gitlab.com/VTTE/sitios-vtte
PHP | 323 lines | 126 code | 50 blank | 147 comment | 7 complexity | e37891d54bf902ed794d15d97e67a66b MD5 | raw file
  1. <?php
  2. if ( ! class_exists( "Yoast_Product", false ) ) {
  3. /**
  4. * Class Yoast_Product
  5. *
  6. * @todo create a license class and store an object of it in this class
  7. */
  8. class Yoast_Product {
  9. /**
  10. * @var string The URL of the shop running the EDD API.
  11. */
  12. protected $api_url;
  13. /**
  14. * @var string The item name in the EDD shop.
  15. */
  16. protected $item_name;
  17. /**
  18. * @var string The theme slug or plugin file
  19. */
  20. protected $slug;
  21. /**
  22. * @var string The version number of the item
  23. */
  24. protected $version;
  25. /**
  26. * @var string The absolute url on which users can purchase a license
  27. */
  28. protected $item_url;
  29. /**
  30. * @var string Absolute admin URL on which users can enter their license key.
  31. */
  32. protected $license_page_url;
  33. /**
  34. * @var string The text domain used for translating strings
  35. */
  36. protected $text_domain;
  37. /**
  38. * @var string The item author
  39. */
  40. protected $author;
  41. /**
  42. * @var string Relative file path to the plugin.
  43. */
  44. protected $file;
  45. /** @var int Product ID in backend system for quick lookup */
  46. protected $product_id;
  47. /** @var string URL referring to the extension page */
  48. protected $extension_url;
  49. /**
  50. * Yoast_Product constructor.
  51. *
  52. * @param string $api_url The URL of the shop running the EDD API.
  53. * @param string $item_name The item name in the EDD shop.
  54. * @param string $slug The slug of the plugin, for shiny updates this needs to be a valid HTML id.
  55. * @param string $version The version number of the item.
  56. * @param string $item_url The absolute url on which users can purchase a license.
  57. * @param string $license_page_url Absolute admin URL on which users can enter their license key.
  58. * @param string $text_domain The text domain used for translating strings.
  59. * @param string $author The item author.
  60. * @param string $file The relative file path to the plugin.
  61. * @param int $product_id The ID of the product in the backend system.
  62. */
  63. public function __construct( $api_url, $item_name, $slug, $version, $item_url = '', $license_page_url = '#', $text_domain = 'yoast', $author = 'Yoast', $file = '', $product_id = 0 ) {
  64. $this->set_api_url( $api_url );
  65. $this->set_item_name( $item_name );
  66. $this->set_slug( $slug );
  67. $this->set_version( $version );
  68. $this->set_item_url( $item_url );
  69. $this->set_text_domain( $text_domain );
  70. $this->set_author( $author );
  71. $this->set_file( $file );
  72. $this->set_product_id( $product_id );
  73. $this->set_license_page_url( $license_page_url );
  74. }
  75. /**
  76. * @param string $api_url
  77. */
  78. public function set_api_url( $api_url ) {
  79. $this->api_url = $api_url;
  80. }
  81. /**
  82. * @return string
  83. */
  84. public function get_api_url() {
  85. return $this->api_url;
  86. }
  87. /**
  88. * @param string $author
  89. */
  90. public function set_author( $author ) {
  91. $this->author = $author;
  92. }
  93. /**
  94. * @return string
  95. */
  96. public function get_author() {
  97. return $this->author;
  98. }
  99. /**
  100. * @param string $item_name
  101. */
  102. public function set_item_name( $item_name ) {
  103. $this->item_name = $item_name;
  104. }
  105. /**
  106. * @return string
  107. */
  108. public function get_item_name() {
  109. return $this->item_name;
  110. }
  111. /**
  112. * @param string $item_url
  113. */
  114. public function set_item_url( $item_url ) {
  115. if ( empty( $item_url ) ) {
  116. $item_url = $this->api_url;
  117. }
  118. $this->item_url = $item_url;
  119. }
  120. /**
  121. * @return string
  122. */
  123. public function get_item_url() {
  124. return $this->item_url;
  125. }
  126. /**
  127. * @param string $license_page_url
  128. */
  129. public function set_license_page_url( $license_page_url ) {
  130. if ( is_admin() && is_multisite() ) {
  131. if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
  132. require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  133. }
  134. if ( is_plugin_active_for_network( $this->get_file() ) ) {
  135. $this->license_page_url = network_admin_url( $license_page_url );
  136. return;
  137. }
  138. }
  139. $this->license_page_url = admin_url( $license_page_url );
  140. }
  141. /**
  142. * @return string
  143. */
  144. public function get_license_page_url() {
  145. return $this->license_page_url;
  146. }
  147. /**
  148. * @param string $slug
  149. */
  150. public function set_slug( $slug ) {
  151. $this->slug = $slug;
  152. }
  153. /**
  154. * @return string
  155. */
  156. public function get_slug() {
  157. return $this->slug;
  158. }
  159. /**
  160. * Returns the dirname of the slug and limits it to 15 chars
  161. *
  162. * @return string
  163. */
  164. public function get_transient_prefix() {
  165. return substr( md5( $this->file ), 0, 15 );
  166. }
  167. /**
  168. * @param string $text_domain
  169. */
  170. public function set_text_domain( $text_domain ) {
  171. $this->text_domain = $text_domain;
  172. }
  173. /**
  174. * @return string
  175. */
  176. public function get_text_domain() {
  177. return $this->text_domain;
  178. }
  179. /**
  180. * @param string $version
  181. */
  182. public function set_version( $version ) {
  183. $this->version = $version;
  184. }
  185. /**
  186. * @return string
  187. */
  188. public function get_version() {
  189. return $this->version;
  190. }
  191. /**
  192. * Returns the file path relative to the plugins folder
  193. *
  194. * @return string
  195. */
  196. public function get_file() {
  197. /*
  198. * Fall back to the slug for BC reasons.
  199. *
  200. * We used to pass the file to the slug field, but this isn't supported with the shiny updates in WordPress.
  201. * WordPress uses the slug in the HTML as an ID and a slash isn't a valid
  202. */
  203. return empty( $this->file ) ? $this->slug : $this->file;
  204. }
  205. /**
  206. * Sets the file path relative to the plugins folder
  207. *
  208. * @param string $file Relative file path to the plugin.
  209. */
  210. public function set_file( $file ) {
  211. $this->file = $file;
  212. }
  213. /**
  214. * Return the Product ID
  215. *
  216. * @return int
  217. */
  218. public function get_product_id() {
  219. return $this->product_id;
  220. }
  221. /**
  222. * Set the product ID
  223. *
  224. * @param int $product_id Product ID to set.
  225. */
  226. public function set_product_id( $product_id ) {
  227. $this->product_id = (int) $product_id;
  228. }
  229. /**
  230. * Gets a Google Analytics Campaign url for this product
  231. *
  232. * @param string $link_identifier
  233. *
  234. * @return string The full URL
  235. */
  236. public function get_tracking_url( $link_identifier = '' ) {
  237. return $this->add_campaign_attributes( $this->get_item_url(), $link_identifier );
  238. }
  239. /**
  240. * Returns the extension url if set, otherwise it will be the tracking url.
  241. *
  242. * @param string $link_identifier
  243. *
  244. * @return string
  245. */
  246. public function get_extension_url( $link_identifier = '' ) {
  247. if ( $this->extension_url ) {
  248. return $this->add_campaign_attributes( $this->extension_url, $link_identifier );
  249. }
  250. return $this->get_tracking_url( $link_identifier );
  251. }
  252. /**
  253. * Sets the extension url.
  254. *
  255. * @param string $extension_url
  256. */
  257. public function set_extension_url( $extension_url ) {
  258. $this->extension_url = $extension_url;
  259. }
  260. private function add_campaign_attributes( $url, $link_identifier ) {
  261. $tracking_vars = array(
  262. 'utm_campaign' => $this->get_item_name() . ' licensing',
  263. 'utm_medium' => 'link',
  264. 'utm_source' => $this->get_item_name(),
  265. 'utm_content' => $link_identifier
  266. );
  267. // URL encode tracking vars.
  268. $tracking_vars = urlencode_deep( $tracking_vars );
  269. $query_string = build_query( $tracking_vars );
  270. return $url . '#' . $query_string;
  271. }
  272. }
  273. }