Ejemplo n.º 1
0
function TSpell_redirect_call() {
    if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
            $postText = trim(  file_get_contents( 'php://input' )  );

    $url = $_GET['url'];

	$service = apply_filters( 'atd_service_domain', 'service.afterthedeadline.com' );
	if ( defined('WPLANG') ) {
		if ( strpos(WPLANG, 'pt') !== false )
			$service = 'pt.service.afterthedeadline.com';
		else if ( strpos(WPLANG, 'de') !== false )
			$service = 'de.service.afterthedeadline.com';
		else if ( strpos(WPLANG, 'es') !== false )
			$service = 'es.service.afterthedeadline.com';
		else if ( strpos(WPLANG, 'fr') !== false )
			$service = 'fr.service.afterthedeadline.com';
	}
	$user = wp_get_current_user();
	$guess = strcmp( TSpell_get_setting( $user->ID, 'TSpell_guess_lang' ), "true" ) == 0 ? "true" : "false";

    $data = TSpell_http_post( $postText . "&guess=$guess", defined('ATD_HOST') ? ATD_HOST : $service, $url, defined('ATD_PORT') ? ATD_PORT : 80 );

    header( 'Content-Type: text/xml' );

	if ( !empty($data[1]) )
		echo $data[1];

	die();
}
function TSpell_load_submit_check_javascripts() {
	global $pagenow;

	$user = wp_get_current_user();
	if ( ! $user || $user->ID == 0 )
		return;

	if ( TSpell_should_load_on_page() ) {
		$atd_check_when = TSpell_get_setting( $user->ID, 'TSpell_check_when' );

		if ( !empty( $atd_check_when ) ) {
			$check_when = array();
			/* Set up the options in json */
			foreach( explode( ',', $atd_check_when ) as $option ) {
				$check_when[$option] = true;
			}
			echo '<script type="text/javascript">' . "\n";
			echo 'TSpell_check_when = ' . json_encode( (object) $check_when ) . ";\n";
			echo '</script>' . "\n";
		}
	}
}
function TSpell_display_unignore_form() {

	if ( ! TSpell_is_allowed() )
		return;

	$user = wp_get_current_user();

	if ( ! $user || $user->ID == 0 )
		return;

	$ignores = TSpell_get_setting( $user->ID, 'TSpell_ignored_phrases' );
?>
<script>
function atd_show_phrases( ignored )
{
	var element = jQuery( '#atd_ignores' ),
	    items   = [],
	    delLink;

	ignored.sort();

	element.empty();
	for ( var i = 0; i < ignored.length; i++ ) {
		if ( ignored[i].length > 0 ) {
			delLink = jQuery( '<span id="atd_' + i + '">&nbsp;</span>' );
			delLink
				.text( delLink.text() + ignored[i] )
				.prepend( jQuery( '<a class="ntdelbutton">X</a>' ).data( 'ignored', ignored[i] ) );
			element.append( delLink ).append( '<br />' );
		}
	}
}

function atd_unignore( phrase ) {
	// get the ignored values and remove the unwanted phrase
	var ignored = jQuery( '#TSpell_ignored_phrases' ).val().split( /,/g );
        ignored = jQuery.map(ignored, function(value, index) { return value == phrase ? null : value; });
        jQuery( '#TSpell_ignored_phrases' ).val( ignored.join(',') );

	// update the UI
	atd_show_phrases( ignored );

	// show a nifty message to the user
    jQuery( '#TSpell_message' ).show();
}

function atd_ignore () {
	// get the ignored values and update the hidden field
	var ignored = jQuery( '#TSpell_ignored_phrases' ).val().split( /,/g );

    jQuery.map(jQuery( '#TSpell_add_ignore' ).val().split(/,\s*/g), function(value, index) { ignored.push(value); });

    jQuery( '#TSpell_ignored_phrases' ).val( ignored.join(',') );

	// update the UI
	atd_show_phrases( ignored );
	jQuery( '#TSpell_add_ignore' ).val('');

	// show that nifteroo messaroo to the useroo
    jQuery( '#TSpell_message' ).show();
}

function atd_ignore_init() {
	jQuery( '#TSpell_message' ).hide();
	jQuery( '#atd_ignores' ).delegate( 'a', 'click', function() {
		atd_unignore( jQuery(this).data( 'ignored' ) );
		return false;
	} );
	atd_show_phrases( jQuery( '#TSpell_ignored_phrases' ).val().split( /,/g ) );
}

// document.ready() does not execute in IE6 unless it's at the bottom of the page. oi!
if (navigator.appName == 'Microsoft Internet Explorer')
	setTimeout( atd_ignore_init, 2500 );
else
	jQuery( document ).ready( atd_ignore_init );
</script>
   <input type="hidden" name="TSpell_ignored_phrases" id="TSpell_ignored_phrases" value="<?php echo esc_attr( $ignores ); ?>">

          <p style="font-weight: bold"><?php _e( 'Ignored Phrases', 'tinymce-spellcheck' ); ?></font>

          <p><?php _e( 'Identify words and phrases to ignore while proofreading your posts and pages:', 'tinymce-spellcheck' ); ?></p>

          <p><input type="text" id="TSpell_add_ignore" name="TSpell_add_ignore"> <input type="button" value="<?php _e( 'Add', 'tinymce-spellcheck' ); ?>" onclick="javascript:atd_ignore()"></p>

          <div class="tagchecklist" id="atd_ignores"></div>

          <div class="plugin-update-tr" id="TSpell_message" style="display: none">
          <div class="update-message"><strong><?php _e( 'Be sure to click "Update Profile" at the bottom of the screen to save your changes.', 'tinymce-spellcheck' ); ?></strong></div>
          </div>

         </td>
      </tr>
   </table>

<?php
}
function TSpell_get_options( $user_id, $name ) {
	$options_raw = TSpell_get_setting( $user_id, $name, 'single' );

	$options = array();
	$options['name'] = $name;

	if ( $options_raw )
		foreach ( explode( ',', $options_raw ) as $option )
			$options[ $option ] = 1;

	return $options;
}