PluginProbe
Polylang / 2.8.3
Polylang v2.8.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / modules / lingotek / lingotek.php

lingotek.php in Polylang 2.8.3, at modules/lingotek/lingotek.php

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