PLL_Lingotek

Class to manage Lingotek ads.

Defined (1)

The class is defined in the following location(s).

/lingotek/lingotek.php  
  1. class PLL_Lingotek { 
  2. const LINGOTEK = 'lingotek-translation/lingotek.php'; 
  3.  
  4. /** 
  5. * Init 
  6. * @since 1.7.7 
  7. */ 
  8. public function init() { 
  9. $options = get_option( 'polylang' ); 
  10.  
  11. // The Lingotek tab 
  12. add_filter( 'pll_settings_tabs', array( $this, 'add_tab' ) ); 
  13. add_action( 'pll_settings_active_tab_lingotek', array( $this, 'display_tab' ) ); 
  14.  
  15. if ( PLL_SETTINGS && isset( $_GET['page'] ) && 'mlang_lingotek' == $_GET['page'] ) { 
  16. add_action( 'admin_print_styles', array( $this, 'print_css' ) ); 
  17.  
  18. // The pointer 
  19. $content = __( 'You*ve just upgraded to the latest version of Polylang! Would you like to automatically translate your website for free?', 'polylang' ); 
  20.  
  21. $buttons = array( 
  22. array( 
  23. 'label' => __( 'Close' ),  
  24. ),  
  25. array( 
  26. 'label' => __( 'Learn more', 'polylang' ),  
  27. 'link' => admin_url( 'admin.php?page=mlang&tab=lingotek' ),  
  28. ),  
  29. ); 
  30.  
  31. if ( $link = $this->get_activate_link() ) { 
  32. $content .= ' ' . __( 'Click on Activate Lingotek to start translating.', 'polylang' ); 
  33.  
  34. $buttons[] = array( 
  35. 'label' => __( 'Activate Lingotek', 'polylang' ),  
  36. 'link' => str_replace( '&', '&', $link ), // wp_nonce_url escapes the url for html display. Here we want it for js 
  37. ); 
  38.  
  39. $args = array( 
  40. 'pointer' => 'pll_lgt',  
  41. 'id' => empty( $options['previous_version'] ) ? 'nav-tab-lingotek' : 'wp-admin-bar-languages',  
  42. 'position' => array( 
  43. 'edge' => 'top',  
  44. 'align' => 'left',  
  45. ),  
  46. 'width' => 400,  
  47. 'title' => __( 'Congratulations!', 'polylang' ),  
  48. 'content' => $content,  
  49. 'buttons' => $buttons,  
  50. ); 
  51.  
  52. new PLL_Pointer( $args ); 
  53.  
  54. /** 
  55. * Adds the Lingotek tab in Polylang settings 
  56. * @since 1.7.7 
  57. * @param array $tabs list of tabs 
  58. * @return array modified liste of tabs 
  59. */ 
  60. public function add_tab( $tabs ) { 
  61. $tabs['lingotek'] = 'Lingotek'; 
  62. return $tabs; 
  63.  
  64. /** 
  65. * Displays the content in the Lingotek tab 
  66. * @since 1.7.7 
  67. */ 
  68. public function display_tab() { 
  69. $activate_link = $this->get_activate_link(); 
  70.  
  71. $links = array( 
  72. 'activate' => array( 
  73. 'label' => is_plugin_active( self::LINGOTEK ) ? __( 'Activated', 'polylang' ) : __( 'Activate', 'polylang' ),  
  74. 'link' => $activate_link,  
  75. 'classes' => 'button button-primary' . ( $activate_link ? '' : ' disabled' ),  
  76. ),  
  77. 'translation' => array( 
  78. 'label' => __( 'Request Translation', 'polylang' ),  
  79. 'link' => 'http://www.lingotek.com/wordpress/translation_bid',  
  80. 'new_tab' => true,  
  81. 'classes' => 'button button-primary',  
  82. ),  
  83. 'services' => array( 
  84. 'label' => __( 'Request Services', 'polylang' ),  
  85. 'link' => 'http://www.lingotek.com/wordpress/extra_services',  
  86. 'new_tab' => true,  
  87. 'classes' => 'button button-primary',  
  88. ); 
  89.  
  90. printf( '<p>%s</p>', esc_html__( 'Polylang is now fully integrated with Lingotek, a professional translation management system!', 'polylang' ) ); 
  91.  
  92. $this->box( 
  93. __( 'Automatically Translate My Site', 'polylang' ),  
  94. __( 'Polylang is now fully integrated with Lingotek!', 'polylang' ),  
  95. array( 
  96. __( 'Access free machine translation for your site for up to 100, 000 characters.', 'polylang' ),  
  97. __( 'Machine translation is an excellent option if you\'re on a tight budget, looking for near-instant results, and are okay with less-than-perfect quality.', 'polylang' ),  
  98. ),  
  99. array_intersect_key( $links, array_flip( array( 'activate' ) ) ),  
  100. 'image01.gif' 
  101. ); 
  102.  
  103. $this->box( 
  104. __( 'Translation Management System', 'polylang' ),  
  105. __( 'Do you need to connect to a professional translation management system?', 'polylang' ),  
  106. array( 
  107. __( 'Access free machine translation for your site for up to 100, 000 characters.', 'polylang' ),  
  108. __( 'Access an online translator workbench.', 'polylang' ),  
  109. __( 'Have linguists compare side-by-side versions of original and translated text.', 'polylang' ),  
  110. __( 'Save and re-use previously translated material (leverage translation memory (TM)).', 'polylang' ),  
  111. ),  
  112. array_intersect_key( $links, array_flip( array( 'activate' ) ) ),  
  113. 'image02.png' 
  114. ); 
  115.  
  116. $this->box( 
  117. __( 'Professionally Translate My Site', 'polylang' ),  
  118. __( 'Do you need to professionally translate your site?', 'polylang' ),  
  119. array( 
  120. __( 'Start the process of getting a professional translation bid.', 'polylang' ),  
  121. __( 'Activate account so Lingotek can get an accurate count of how many words you have on your site and which languages you wish to translate into.', 'polylang' ),  
  122. __( 'Once activated click on the request translation bid and a certified translation project manager will contact you to give a no obligations translation bid.', 'polylang' ),  
  123. ),  
  124. array_intersect_key( $links, array_flip( array( 'activate', 'translation' ) ) ),  
  125. 'image03.png' 
  126. ); 
  127.  
  128. $this->box( 
  129. __( 'Need Extra Services?', 'polylang' ),  
  130. __( 'Do you need help translating your site?', 'polylang' ),  
  131. array( 
  132. __( 'Start the process of getting extra services.', 'polylang' ),  
  133. __( 'Do you need someone to run your localization project?', 'polylang' ),  
  134. __( 'Do you need customized workflows?', 'polylang' ),  
  135. __( 'Do you have existing Translation Memories you would like to use?', 'polylang' ),  
  136. __( 'Do you need help creating glossaries and terminologies?', 'polylang' ),  
  137. ),  
  138. array_intersect_key( $links, array_flip( array( 'activate', 'services' ) ) ),  
  139. 'image04.png' 
  140. ); 
  141.  
  142.  
  143. /** 
  144. * Styles the content of the Lingotek tab 
  145. * @since 1.7.7 
  146. */ 
  147. public function print_css() { ?> 
  148. <style type="text/css"> 
  149. .ltk-feature { 
  150. text-align: left; 
  151. float: left; 
  152. width: 310px; 
  153. padding: 0px; 
  154. border: 1px solid #ddd; 
  155. margin-right: 3px; 
  156. margin-bottom: 3px; 
  157. height: 630px; 
  158. background: #fafafa; 
  159. .ltk-feature h3 { 
  160. height: 1em; 
  161. .ltk-feature .ltk-image { 
  162. text-align: center; 
  163. .ltk-feature img { 
  164. margin: 10px; 
  165. width: 180px; 
  166. height: 180px; 
  167. height: auto; 
  168. .ltk-feature ul { 
  169. margin-left: 10px; 
  170. .ltk-feature ul li { 
  171. list-style: inside disc; 
  172. list-style-position: outside; 
  173. padding-left: 0; 
  174. .ltk-feature .ltk-desc { 
  175. height: 3em; 
  176. width: 100%; 
  177. .ltk-feature .ltk-upper { 
  178. background: #fff; 
  179. padding: 20px; 
  180. .ltk-feature .ltk-lower { 
  181. padding: 5px 20px 0px 20px; 
  182. border-top: 1px solid #eee; 
  183.  
  184. text-align: left; 
  185. font-size: 95%; 
  186.  
  187. @media screen and ( max-width: 620px ) { 
  188. .ltk-feature { 
  189. height: auto; 
  190. padding-bottom: 20px; 
  191. </style><?php 
  192.  
  193. /** 
  194. * Outputs the content of each box 
  195. * @since 1.7.7 
  196. * @param string $title 
  197. * @param string $desc 
  198. * @param array $list 
  199. * @param array $links 
  200. * @param string $img 
  201. */ 
  202. protected function box( $title, $desc, $list, $links, $img ) {?> 
  203. <div class="ltk-feature"> 
  204. <div class="ltk-upper"> 
  205. <div class="ltk-image"> 
  206. <img src="<?php echo esc_url( plugins_url( $img, __FILE__ ) );?> " width="220" height="220"/> 
  207. </div> 
  208. <h3><?php echo esc_html( $title ); ?></h3> 
  209. <p class="ltk-desc"><?php echo esc_html( $desc ); ?></p><?php 
  210. foreach ( $links as $link_details ) { 
  211. printf( 
  212. '<a class = "%s" href = "%s"%s>%s</a> ',  
  213. esc_attr( $link_details['classes'] ),  
  214. esc_url( $link_details['link'] ),  
  215. empty( $link_details['new_tab'] ) ? '' : ' target = "_blank"',  
  216. esc_html( $link_details['label'] ) 
  217. ); 
  218. } ?> 
  219. </div> 
  220. <div class="ltk-lower"> 
  221. <ul><?php 
  222. foreach ( $list as $item ) { 
  223. printf( '<li>%s</li>', esc_html( $item ) ); 
  224. } ?> 
  225. </ul> 
  226. <a href="http://www.lingotek.com/wordpress" target = "_blank"><?php esc_html_e( 'Learn more...', 'polylang' ) ?></a> 
  227. </div> 
  228.  
  229. </div><?php 
  230.  
  231. /** 
  232. * Get a link to install / activate Lingotek 
  233. * depending on user rights and if plugin is already installed 
  234. * @since 1.7.7 
  235. * @return string 
  236. */ 
  237. protected function get_activate_link() { 
  238. require_once ABSPATH . '/wp-admin/includes/plugin.php'; 
  239.  
  240. if ( ! array_key_exists( self::LINGOTEK, get_plugins() ) ) { 
  241. if ( current_user_can( 'install_plugins' ) ) { 
  242. $plugin = dirname( self::LINGOTEK ); 
  243. return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin ), 'install-plugin_' . $plugin ); 
  244.  
  245. elseif ( current_user_can( 'activate_plugins' ) ) { 
  246. if ( ! is_plugin_active( self::LINGOTEK ) ) { 
  247. return wp_nonce_url( 'plugins.php?action=activate&plugin=' . self::LINGOTEK, 'activate-plugin_' . self::LINGOTEK ); 
  248.  
  249. return '';