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