コード例 #1
0
ファイル: helpers.php プロジェクト: QuezonMe/skelet
 function paf_print_option_type_textarea($option_def)
 {
     $option_id = key($option_def);
     $option = $option_def[$option_id];
     if ('~' === K::get_var('description', $option)) {
         $option['description'] = paf_option_return_dump($option_id);
     }
     $style = '';
     foreach (array('height', 'width') as $prop) {
         $style .= K::get_var($prop, $option) ? sprintf('%:%;', $prop, $option[$prop]) : '';
     }
     K::textarea('paf[' . $option_id . ']', array('class' => K::get_var('cols', $option) ? '' : 'large-text', 'cols' => K::get_var('cols', $option), 'rows' => K::get_var('rows', $option), 'style' => $style, 'data-paf-conditions' => K::get_var('conditions', $option) ? urlencode(json_encode(K::get_var('conditions', $option), JSON_FORCE_OBJECT)) : null, 'data-paf-default' => K::get_var('default', $option)), array('value' => isset($option['value']) ? $option['value'] : paf($option_id), 'editor' => K::get_var('editor', $option, FALSE), 'editor_height' => K::get_var('editor_height', $option), 'format' => sprintf(paf_option_return_format('textarea'), paf_option_return_title($option_def), K::get_var('description', $option, '')), 'media_buttons' => K::get_var('media_buttons', $option, TRUE), 'teeny' => K::get_var('teeny', $option), 'textarea_rows' => K::get_var('textarea_rows', $option, 20)));
 }
コード例 #2
0
function skelet_tinyMCE_php($tag)
{
    global $paf_shortcodes;
    $select2_enqueued = false;
    $protocol = is_ssl() ? 'https' : 'http';
    // Head
    printf('<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title>');
    // CSS
    printf('<link rel="stylesheet" href="%s" />', admin_url('css/common' . (is_rtl() ? '-rtl' : '') . '.css'));
    printf('<link rel="stylesheet" href="%s" />', admin_url('css/forms' . (is_rtl() ? '-rtl' : '') . '.css'));
    printf('<link rel="stylesheet" href="%s" />', site_url('wp-includes/css/dashicons' . (is_rtl() ? '-rtl' : '') . '.min.css'));
    printf('<link rel="stylesheet" href="%s" />', site_url('wp-includes/css/buttons' . (is_rtl() ? '-rtl' : '') . '.min.css'));
    print '<style>body { height: auto; margin: 0; min-width: 0; padding: 1em; }</style>';
    paf_asset_css('paf');
    // JS
    printf('<script src="%s"></script>', "{$protocol}://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js");
    printf('<script src="%s"></script>', "{$protocol}://cdnjs.cloudflare.com/ajax/libs/jquery.serializeJSON/1.2.0/jquery.serializeJSON.min.js");
    paf_asset_js('paf');
    ob_start();
    ?>
	<script>
		var paf;
		var shortcode = '';
		var wrap = <?php 
    echo K::get_var('wrap', $paf_shortcodes[$tag]) ? 'true' : 'false';
    ?>
;

		jQuery( document ).ready( function ( $ ) {

			/* Fill content field with selected text if any */
			var content = parent.tinymce.activeEditor.selection.getContent( { format : 'text' } );
			$( '#content' ).val( content );

			// Update shortcode
			$( 'input,select,textarea', 'form' ).on( 'change keyup', function() { $( 'form' ).change(); } );

			// Autoselect shortcode
			$( "#shortcode" ).mouseover( function() { $( this ).select(); } );

			/**
			 * Bind to form events
			 *
			 * - On submit: Fill the WP editor
			 * - On change: update the shortcode value
			 */
			$( 'form' ).on( 'submit change', function( e ) {

				e.preventDefault();

				shortcode = '';
				paf = $( this ).serializeJSON().paf;
				content = $( '#content' ).val();

				if( 'undefined' === typeof paf ) {
					paf = {};
				}

				// Build the shortcode
				Object.keys( paf ).map( function(v) {
					if( 'undefined' !== paf[ v ] && paf[ v ] ) {
						shortcode += ' '
							+ v
							+ '="'
							+ paf[ v ].toString().split().join().replace( '"', '\\"', 'g' )
							+ '"'
						;
					}
				} );

				if( wrap ) {
					shortcode = "[<?php 
    echo $tag;
    ?>
" + shortcode + "]"
						+ content
						+ "[/<?php 
    echo $tag;
    ?>
]"
					;
				} else {
					shortcode = "[<?php 
    echo $tag;
    ?>
" + shortcode + "]";
				}

				// Update the demo
				$( "#shortcode" ).val( shortcode );

				// Fill the editor and close
				if ( 'submit' === e.type ) {
					parent.tinymce.activeEditor.execCommand( "mceInsertContent", false, shortcode );
					parent.tinymce.activeEditor.windowManager.close( window );
				}
			} ).change();
		} );
	</script>
	<?php 
    print JSMin::minify(ob_get_clean());
    // Close head
    print '</head><body class="wp-core-ui">';
    // Fields
    $parameters = $paf_shortcodes[$tag]['parameters'];
    echo '<form id="paf-form" action = "">';
    foreach ($parameters as $k => $v) {
        // Validate title
        $v['title'] = k::get_var('title', $v, $k);
        // Print option
        paf_print_option($k, $v);
        if ('select' === K::get_var('type', $v)) {
            printf('<link rel="stylesheet" href="%s" />', "{$protocol}://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css");
            printf('<script src="%s"></script>', "{$protocol}://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js");
            print "<script>jQuery( document ).ready( function( \$ ) { \$( 'select' ).select2(); } );</script>";
            $select2_enqueued = true;
        }
    }
    // Content field
    if (K::get_var('wrap', $paf_shortcodes[$tag])) {
        K::textarea('content', array('class' => 'large-text', 'id' => 'content'), array('format' => '<p><label><strong>Content:</strong>:textarea</label></p>'));
    }
    // Buttons
    echo '<hr />';
    echo '<p><label><strong>Shortcode:</strong><input type="text" class="large-text" id="shortcode" value=""/></label></p>';
    echo '<hr />';
    echo '<p>';
    K::input('submit', array('class' => 'button button-large button-primary aligncenter	', 'type' => 'submit', 'value' => 'Add shortcode'));
    echo ' ';
    K::wrap('Reset', array('class' => 'button button-large paf-reset', 'href' => '#', 'id' => 'paf-reset'), array('in' => 'a'));
    echo '</p>';
    // Close document
    echo '</form></body></html>';
    // C ya!
    return ob_get_clean();
}