PluginProbe
Polylang / 3.2.2
Polylang v3.2.2
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 3.2.2, at modules/lingotek/lingotek.php

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