Plugin Directory

Changeset 1005532


Ignore:
Timestamp:
10/11/2014 08:05:50 AM (11 years ago)
Author:
toxicToad
Message:
  • Tested up to WordPress 4.0
  • Added Containing Element option: Confine invaders to a specific page element
  • Added Z-index support: Configure invaders z-index for layering in document
  • Updated Admin screen
  • Updated ReadMe
  • Updated Spritely version
Location:
jellyfish-invaders
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • jellyfish-invaders/trunk/jellyfish_invaders.css

    r648542 r1005532  
    1 /* 
     1/*
    22    Document   : jellyfish_invaders.css
    33    Created on : 02/01/2013, 1:12:13 PM
     
    1414    width: 220px;
    1515    height: 180px;
    16     z-index: 1000;
    1716}
    1817.medium-invader {
     
    2322    width: 110px;
    2423    height: 90px;
    25     z-index: 1000;
    2624}
    2725.small-invader {
     
    3230    width: 55px;
    3331    height: 45px;
    34     z-index: 1000;
    3532}
  • jellyfish-invaders/trunk/jellyfish_invaders.php

    r822235 r1005532  
    55  Description: Randomly animates retro space invaders on your WordPress blog
    66  Author: Robert Miller <rob@strawberryjellyfish.com>
    7   Version: 0.8.1
     7  Version: 0.8
    88  Author URI: http://strawberryjellyfish.com/
    99 */
     
    3030 */
    3131
    32 
    3332// set default options
    34 register_activation_hook( __FILE__,'jellyfish_invaders_default_options' );
     33register_activation_hook( __FILE__, 'jellyfish_invaders_default_options' );
    3534
    3635// add admin page
     
    3837
    3938// Register and define the settings
    40 add_action('admin_init', 'jellyfish_invaders_admin_init');
    41 
    42 // enqueue javascript and css
    43 
    44 $jellyfish_invaders_options = get_option('jellyfish_invaders_options');
     39add_action( 'admin_init', 'jellyfish_invaders_admin_init' );
     40
     41// enqueue JavaScript and css
     42
     43$jellyfish_invaders_options = get_option( 'jellyfish_invaders_options' );
    4544
    4645// only need scripts if viewing blog and invaders are enabled
    47 if (!is_admin() && ($jellyfish_invaders_options['enable'] == true)) {
    48     add_action('wp_enqueue_scripts', 'jellyfish_invaders_queue_scripts');
     46if ( !is_admin() && ( $jellyfish_invaders_options['enable'] == true ) ) {
     47    add_action( 'wp_enqueue_scripts', 'jellyfish_invaders_queue_scripts' );
    4948}
    5049
     
    5352 * Plugin Functions
    5453 */
    55 
    5654
    5755function jellyfish_invaders_queue_scripts() {
     
    5957    // and css when invaders are needed. This is slightly complicated by the fact
    6058    // we can have them displaying on a per post basis.
    61    
    62     $jellyfish_invaders_options = get_option('jellyfish_invaders_options');
    63     $need_invaders = false;   
    64 
    65     if (!is_admin() && ($jellyfish_invaders_options['enable'] == true)) {
     59
     60    $jellyfish_invaders_options = get_option( 'jellyfish_invaders_options' );
     61    $need_invaders = false;
     62
     63    if ( !is_admin() && ( $jellyfish_invaders_options['enable'] == true ) ) {
    6664        // most likely we need to print scripts
    67        $need_invaders = true;
    68        if ($jellyfish_invaders_options['use_custom_field'] == true) {
    69            // but now only show invaders on specific pages
    70            // check we need them before queueing up the js and css
    71            if (is_single() OR is_page()) {
    72                 $cv = get_post_meta(get_the_ID(), 'jellyfish_invaders',true);
    73                 if ( ($cv != 'true') && ($cv != 'on')){ 
     65        $need_invaders = true;
     66        if ( $jellyfish_invaders_options['use_custom_field'] == true ) {
     67            // but now only show invaders on specific pages
     68            // check we need them before queueing up the js and css
     69            if ( is_single() or is_page() ) {
     70                $cv = get_post_meta( get_the_ID(), 'jellyfish_invaders', true );
     71                if ( ( $cv != 'true' ) && ( $cv != 'on' ) ) {
    7472                    // abort: no custom field, no invaders needed
    7573                    $need_invaders = false;
    7674                }
    77            } else {
     75            } else {
    7876                // abort: not a single page or post can't show them anyway
    7977                $need_invaders = false;
    80            }
     78            }
    8179        }
    8280    }
    8381
    84     if ($need_invaders) {
    85     //enqueue Spritely jquery library and js for animation and necessary css to page footer
    86         wp_register_script( 'spritely', plugins_url( 'js/jquery.spritely-0.6.js', __FILE__ ), array('jquery'), '', true );
     82    if ( $need_invaders ) {
     83        //enqueue Spritely jQuery library and js for animation and necessary css to page footer
     84        wp_register_script( 'spritely', plugins_url( 'js/jquery.spritely.js', __FILE__ ), array( 'jquery' ), '', true );
    8785        wp_enqueue_script( 'spritely' );
    88         wp_enqueue_style( 'jellyfish_invaders_style',plugins_url( 'jellyfish_invaders.css', __FILE__ ) );
    89         add_action('wp_footer', 'jellyfish_invaders_print_script',100);
    90     } 
     86        wp_enqueue_style( 'jellyfish_invaders_style', plugins_url( 'jellyfish_invaders.css', __FILE__ ) );
     87        add_action( 'wp_footer', 'jellyfish_invaders_print_script', 100 );
     88    }
    9189}
    9290
     
    103101        $new_options['number_of_invaders'] = 5;
    104102        $new_options['duration'] = 3000;
    105         $new_options['pause'] = 1000; 
     103        $new_options['pause'] = 1000;
    106104        $new_options['attack_mode'] = 1;
    107105        $new_options['size'] = 2;
     
    110108        $new_options['wiggle'] = true;
    111109        $new_options['random'] = true;
    112         $new_options['no_boundry'] = true;
     110        $new_options['boundary'] = false;
    113111        $new_options['top'] = 0;
    114112        $new_options['bottom'] = 400;
    115113        $new_options['left'] = 0;
    116114        $new_options['right'] = 800;
    117        
    118         $new_options['version'] = "1.0";
    119    
     115        $new_options['z_index'] = 999;
     116        $new_options['container_element'] = "body";
     117
     118        $new_options['version'] = 1.1;
     119
    120120        add_option( 'jellyfish_invaders_options', $new_options );
    121121    } else {
    122122        $existing_options = get_option( 'jellyfish_invaders_options' );
    123123        if ( $existing_options['version'] < 1.1 ) {
    124             //$existing_options['version'] = "1.1";
    125             // add any new options here with version control
     124            // new options with version control
     125            $existing_options['version'] = 1.1;
     126            $existing_options['z_index'] = 999;
     127            $existing_options['container_element'] = "body";
     128            $existing_options['boundary'] = false;
    126129            update_option( 'jellyfish_invaders_options', $existing_options );
    127130        }
    128131    }
    129132}
    130    
     133
    131134
    132135function jellyfish_invaders_config_page() {
     
    136139    <h2>Jellyfish Invaders</h2>
    137140    <form action="options.php" method="post">
    138     <?php settings_fields('jellyfish_invaders_options'); ?>
    139     <?php do_settings_sections('jellyfish_invaders'); ?>
     141    <?php settings_fields( 'jellyfish_invaders_options' ); ?>
     142    <?php do_settings_sections( 'jellyfish_invaders' ); ?>
    140143    <input name="Submit" type="submit" class="button action" value="Save Changes"/>
    141144    </form>
     
    144147}
    145148
    146 function jellyfish_invaders_admin_init(){
     149function jellyfish_invaders_admin_init() {
    147150    register_setting( 'jellyfish_invaders_options', 'jellyfish_invaders_options', 'jellyfish_invaders_validate_options' );
    148     add_settings_section( 'jellyfish_invaders_main', 'Invader Behaviour', 'jellyfish_invaders_behaviour_text', 'jellyfish_invaders');
     151    add_settings_section( 'jellyfish_invaders_main', 'General Settings', 'jellyfish_invaders_behaviour_text', 'jellyfish_invaders' );
    149152    add_settings_field( 'jellyfish_invaders_enable', 'Enable Invaders', 'jellyfish_invaders_enable_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
    150153    add_settings_field( 'jellyfish_invaders_use_custom_field', 'Where to show', 'jellyfish_invaders_use_custom_field_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
    151154    add_settings_field( 'jellyfish_invaders_number_of_invaders', 'Number of Invaders', 'jellyfish_invaders_number_of_invaders_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
    152     add_settings_field( 'jellyfish_invaders_size', 'Invader Size', 'jellyfish_invaders_size_input', 'jellyfish_invaders', 'jellyfish_invaders_main');
    153     add_settings_field( 'jellyfish_invaders_duration', 'Fly Time', 'jellyfish_invaders_duration_input', 'jellyfish_invaders', 'jellyfish_invaders_main');
     155    add_settings_field( 'jellyfish_invaders_size', 'Invader Size', 'jellyfish_invaders_size_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
     156    add_settings_field( 'jellyfish_invaders_duration', 'Fly Time', 'jellyfish_invaders_duration_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
    154157    add_settings_field( 'jellyfish_invaders_pause', 'Pause Time', 'jellyfish_invaders_pause_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
    155158    add_settings_field( 'jellyfish_invaders_random', 'Random', 'jellyfish_invaders_random_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
    156159    add_settings_field( 'jellyfish_invaders_wiggle', 'Wiggle', 'jellyfish_invaders_wiggle_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
    157160    add_settings_field( 'jellyfish_invaders_attack_mode', 'Attack Mode', 'jellyfish_invaders_attack_mode_input', 'jellyfish_invaders', 'jellyfish_invaders_main' );
    158     add_settings_section( 'jellyfish_invaders_boundry', 'Invader Boundries', 'jellyfish_invaders_boundry_text', 'jellyfish_invaders');
    159     add_settings_field( 'jellyfish_invaders_no_boundry', 'Ignore Boundries', 'jellyfish_invaders_no_boundry_input', 'jellyfish_invaders', 'jellyfish_invaders_boundry' );
    160     add_settings_field( 'jellyfish_invaders_top', 'Top', 'jellyfish_invaders_top_input', 'jellyfish_invaders', 'jellyfish_invaders_boundry' );
    161     add_settings_field( 'jellyfish_invaders_left', 'Left', 'jellyfish_invaders_left_input', 'jellyfish_invaders', 'jellyfish_invaders_boundry' );
    162     add_settings_field( 'jellyfish_invaders_right', 'Right', 'jellyfish_invaders_right_input', 'jellyfish_invaders', 'jellyfish_invaders_boundry' );
    163     add_settings_field( 'jellyfish_invaders_bottom', 'Bottom', 'jellyfish_invaders_bottom_input', 'jellyfish_invaders', 'jellyfish_invaders_boundry' );
     161    add_settings_section( 'jellyfish_invaders_advanced', 'Advanced Settings', 'jellyfish_invaders_advanced_text', 'jellyfish_invaders' );
     162    add_settings_field( 'jellyfish_invaders_container_element', 'Containing Element', 'jellyfish_invaders_container_element_input', 'jellyfish_invaders', 'jellyfish_invaders_advanced' );
     163    add_settings_field( 'jellyfish_invaders_z_index', 'Z-index', 'jellyfish_invaders_z_index_input', 'jellyfish_invaders', 'jellyfish_invaders_advanced' );
     164    add_settings_field( 'jellyfish_invaders_boundary', 'Use Electric Fence', 'jellyfish_invaders_boundary_input', 'jellyfish_invaders', 'jellyfish_invaders_advanced' );
     165    add_settings_field( 'jellyfish_invaders_top', 'Fence Top', 'jellyfish_invaders_top_input', 'jellyfish_invaders', 'jellyfish_invaders_advanced' );
     166    add_settings_field( 'jellyfish_invaders_left', 'Fence Left', 'jellyfish_invaders_left_input', 'jellyfish_invaders', 'jellyfish_invaders_advanced' );
     167    add_settings_field( 'jellyfish_invaders_right', 'Fence Right', 'jellyfish_invaders_right_input', 'jellyfish_invaders', 'jellyfish_invaders_advanced' );
     168    add_settings_field( 'jellyfish_invaders_bottom', 'Fence Bottom', 'jellyfish_invaders_bottom_input', 'jellyfish_invaders', 'jellyfish_invaders_advanced' );
    164169}
    165170// Draw the section header
    166171function jellyfish_invaders_behaviour_text() {
    167     echo '<p>Here you can set the number and general behaviour of your invaders, too many invaders may effect system performance!</p>';
     172    echo '';
    168173}
    169174// Draw the section header
    170 function jellyfish_invaders_boundry_text() {
    171     echo '<p>The following settings can be used to define an area on the page that the invaders will appear in. You can use this to confine them to a specific area on your page, to avoid getting in the way of content for example.</p>';
    172     echo '<p>If you just want them to fly free everywhere check the <b>Ignore Boundries</b> checkbox</p> ';
     175function jellyfish_invaders_advanced_text() {
     176    echo '<p>Invaders live in the document body and normally have free
     177    roam of the entire page but you can confine them to within a specific page
     178    element or set up a virtual electric fence to keep them within a box area
     179    you define in pixels.</p> ';
    173180}
    174181
     
    177184    $options = get_option( 'jellyfish_invaders_options' );
    178185    $number_of_invaders = $options['number_of_invaders'];
    179     echo "<input id='number_of_invaders' name='jellyfish_invaders_options[number_of_invaders]' type='text' value='$number_of_invaders' /> ";
     186    $html = "<input id='number_of_invaders' name='jellyfish_invaders_options[number_of_invaders]' type='text' value='$number_of_invaders' size=5/> ";
     187    $html .= '<label for="number_of_invaders"> 1 - 10 is a good number </label>';
     188    echo $html;
    180189}
    181190
     
    183192    $options = get_option( 'jellyfish_invaders_options' );
    184193    $duration = $options['duration'];
    185     echo "<input id='duration' name='jellyfish_invaders_options[duration]' type='text' value='$duration' /> ";
     194    $html = "<input id='duration' name='jellyfish_invaders_options[duration]' type='text' value='$duration' size=5 /> ";
     195    $html .= '<label for="duration">ms (1000 = 1 second)</label>';
     196    echo $html;
    186197}
    187198
     
    189200    $options = get_option( 'jellyfish_invaders_options' );
    190201    $pause = $options['pause'];
    191     echo "<input id='pause' name='jellyfish_invaders_options[pause]' type='text' value='$pause' /> ";
     202    $html = "<input id='pause' name='jellyfish_invaders_options[pause]' type='text' value='$pause' size=5 /> ";
     203    $html .= '<label for="pause">ms</label>';
     204    echo $html;
    192205}
    193206
     
    195208    $options = get_option( 'jellyfish_invaders_options' );
    196209    $html = "<input id='wiggle' name='jellyfish_invaders_options[wiggle]' type='checkbox' ". checked( true, $options['wiggle'], false ). " / > ";
    197     $html .= '<label for="wiggle">Invaders wiggle not rest</label>'; 
     210    $html .= '<label for="wiggle">Invaders wiggle not rest</label>';
    198211    echo $html;
    199212}
     
    202215    $options = get_option( 'jellyfish_invaders_options' );
    203216    $html = "<input id='enable' name='jellyfish_invaders_options[enable]' type='checkbox' ". checked( true, $options['enable'], false ). " / > ";
    204     $html .= '<label for="wiggle">Uncheck this to turn the Invaders off</label>'; 
     217    $html .= '<label for="wiggle">Uncheck this to turn the Invaders off</label>';
    205218    echo $html;
    206219}
     
    209222    $options = get_option( 'jellyfish_invaders_options' );
    210223    $html = "<input id='random' name='jellyfish_invaders_options[random]' type='checkbox' ". checked( true, $options['random'], false ). " / > ";
    211     $html .= '<label for="random">Add some variation to duration and delay</label>'; 
    212     echo $html;
    213 }
    214 
    215 function jellyfish_invaders_use_custom_field_input() { 
     224    $html .= '<label for="random">Add some variation to duration and delay</label>';
     225    echo $html;
     226}
     227
     228function jellyfish_invaders_use_custom_field_input() {
    216229    $options = get_option( 'jellyfish_invaders_options' );
    217230    $use_custom_field = $options['use_custom_field'];
    218     $html = '<input type="radio" id="invader_use_custom_field_one" name="jellyfish_invaders_options[use_custom_field]" value="false"' . checked( false, $use_custom_field, false ) . '/>'; 
    219     $html .= '<label for="invader_size_one">Show Everywhere</label>        ' ; 
    220     $html .= '<input type="radio" id="invader_use_custom_field_two" name="jellyfish_invaders_options[use_custom_field]" value="true"' . checked( true, $use_custom_field, false ) . '/>'; 
    221     $html .= '<label for="invader_size_two">Only on posts or pages with custom field</label>        ' ;
    222     echo $html; 
    223 }
    224 function jellyfish_invaders_size_input() { 
     231    $html = '<input type="radio" id="invader_use_custom_field_one" name="jellyfish_invaders_options[use_custom_field]" value="false"' . checked( false, $use_custom_field, false ) . '/>';
     232    $html .= '<label for="invader_size_one">Show Everywhere</label>        ' ;
     233    $html .= '<br/><input type="radio" id="invader_use_custom_field_two" name="jellyfish_invaders_options[use_custom_field]" value="true"' . checked( true, $use_custom_field, false ) . '/>';
     234    $html .= '<label for="invader_siz
     235    e_two">Only on posts or pages with custom field</label>        ' ;
     236    echo $html;
     237}
     238function jellyfish_invaders_size_input() {
    225239    $options = get_option( 'jellyfish_invaders_options' );
    226240    $size = $options['size'];
    227     $html = '<input type="radio" id="invader_size_one" name="jellyfish_invaders_options[size]" value="1"' . checked( 1, $size, false ) . '/>'; 
    228     $html .= '<label for="invader_size_one">Small</label>        ' ; 
    229     $html .= '<input type="radio" id="invader_size_two" name="jellyfish_invaders_options[size]" value="2"' . checked( 2, $size, false ) . '/>'; 
    230     $html .= '<label for="invader_size_two">Medium</label>        ' ; 
    231     $html .= '<input type="radio" id="invader_size_three" name="jellyfish_invaders_options[size]" value="3"' . checked( 3, $size, false ) . '/>'; 
     241    $html = '<input type="radio" id="invader_size_one" name="jellyfish_invaders_options[size]" value="1"' . checked( 1, $size, false ) . '/>';
     242    $html .= '<label for="invader_size_one">Small</label>        ' ;
     243    $html .= '<br/><input type="radio" id="invader_size_two" name="jellyfish_invaders_options[size]" value="2"' . checked( 2, $size, false ) . '/>';
     244    $html .= '<label for="invader_size_two">Medium</label>        ' ;
     245    $html .= '<br/><input type="radio" id="invader_size_three" name="jellyfish_invaders_options[size]" value="3"' . checked( 3, $size, false ) . '/>';
    232246    $html .= '<label for="invader_size_three">Large</label>  ';
    233     echo $html; 
    234 } 
    235 
    236 function jellyfish_invaders_attack_mode_input() { 
     247    echo $html;
     248}
     249
     250function jellyfish_invaders_attack_mode_input() {
    237251    $options = get_option( 'jellyfish_invaders_options' );
    238252    $attack = $options['attack_mode'];
    239     $html = '<input type="radio" id="invader_attack_mode_one" name="jellyfish_invaders_options[attack_mode]" value="1"' . checked( 1, $attack, false ) . '/>'; 
    240     $html .= '<label for="invader_attack_mode_one">Off</label>        '; 
    241     $html .= '<input type="radio" id="invader_attack_mode_two" name="jellyfish_invaders_options[attack_mode]" value="2"' . checked( 2, $attack, false ) . '/>'; 
    242     $html .= '<label for="invader_attack_mode_two">Solo</label>        '; 
    243     $html .= '<input type="radio" id="invader_attack_mode_three" name="jellyfish_invaders_options[attack_mode]" value="3"' . checked( 3, $attack, false ) . '/>'; 
    244     $html .= '<label for="invader_attack_mode_two">Squadron</label>        ';
    245     echo $html; 
    246 }
    247 
    248 function jellyfish_invaders_no_boundry_input() {
    249     $options = get_option( 'jellyfish_invaders_options' );
    250     $html = "<input id='enable' name='jellyfish_invaders_options[no_boundry]' type='checkbox' ". checked( true, $options['no_boundry'], false ). " / > ";
    251     $html .= '<label for="wiggle">Let them roam entire page (overrides the settings below)</label>'; 
     253    $html = '<input type="radio" id="invader_attack_mode_one" name="jellyfish_invaders_options[attack_mode]" value="1"' . checked( 1, $attack, false ) . '/>';
     254    $html .= '<label for="invader_attack_mode_one">Off</label>        ';
     255    $html .= '<br/><input type="radio" id="invader_attack_mode_two" name="jellyfish_invaders_options[attack_mode]" value="2"' . checked( 2, $attack, false ) . '/>';
     256    $html .= '<label for="invader_attack_mode_two">Solo</label>        ';
     257    $html .= '<br/><input type="radio" id="invader_attack_mode_three" name="jellyfish_invaders_options[attack_mode]" value="3"' . checked( 3, $attack, false ) . '/>';
     258    $html .= '<label for="invader_attack_mode_three">Squadron</label>        ';
     259    echo $html;
     260}
     261
     262function jellyfish_invaders_z_index_input() {
     263    $options = get_option( 'jellyfish_invaders_options' );
     264    $z_index = $options['z_index'];
     265    $html = "<input id='z_index' name='jellyfish_invaders_options[z_index]' type='text' value='$z_index' size=5 /> ";
     266    $html .= '<label for="z_index">Layer invaders behind / in front of other page elements</label>';
     267    echo $html;
     268}
     269
     270function jellyfish_invaders_container_element_input() {
     271    $options = get_option( 'jellyfish_invaders_options' );
     272    $container_element = $options['container_element'];
     273    $html = "<input id='container_element' name='jellyfish_invaders_options[container_element]' type='text' value='$container_element' /> ";
     274    $html .= '<label for="container_element">Element id (eg. #content)</label>';
     275    echo $html;
     276}
     277
     278function jellyfish_invaders_boundary_input() {
     279    $options = get_option( 'jellyfish_invaders_options' );
     280    $html = "<input id='enable' name='jellyfish_invaders_options[boundary]' type='checkbox' ". checked( true, $options['boundary'], false ). " / > ";
     281    $html .= '<label for="enable"> Confine to fenced area (overrides <b>Containing Element</b> option)</label>';
    252282    echo $html;
    253283}
     
    255285    $options = get_option( 'jellyfish_invaders_options' );
    256286    $top = $options['top'];
    257     echo "<input id='top' name='jellyfish_invaders_options[top]' type='text' value='$top' /> ";
     287    $html = "<input id='top' name='jellyfish_invaders_options[top]' type='text' value='$top' size=5 /> ";
     288    $html .= '<label for="top">px</label>';
     289    echo $html;
    258290}
    259291function jellyfish_invaders_left_input() {
    260292    $options = get_option( 'jellyfish_invaders_options' );
    261293    $left = $options['left'];
    262     echo "<input id='left' name='jellyfish_invaders_options[left]' type='text' value='$left' /> ";
     294    $html = "<input id='left' name='jellyfish_invaders_options[left]' type='text' value='$left' size=5 /> ";
     295    $html .= '<label for="left">px</label>';
     296    echo $html;
    263297}
    264298function jellyfish_invaders_right_input() {
    265299    $options = get_option( 'jellyfish_invaders_options' );
    266300    $right = $options['right'];
    267     echo "<input id='right' name='jellyfish_invaders_options[right]' type='text' value='$right' /> ";
     301    $html = "<input id='right' name='jellyfish_invaders_options[right]' type='text' value='$right' size=5 /> ";
     302    $html .= '<label for="right">px</label>';
     303    echo $html;
    268304}
    269305function jellyfish_invaders_bottom_input() {
    270306    $options = get_option( 'jellyfish_invaders_options' );
    271307    $bottom = $options['bottom'];
    272     echo "<input id='bottom' name='jellyfish_invaders_options[bottom]' type='text' value='$bottom' /> ";
    273 }
    274 
    275 
    276 // Validate user input
     308    $html = "<input id='bottom' name='jellyfish_invaders_options[bottom]' type='text' value='$bottom' size=5 /> ";
     309    $html .= '<label for="bottom">px</label>';
     310    echo $html;
     311}
     312
     313
     314// Validate user input
    277315function jellyfish_invaders_validate_options( $input ) {
    278316    $valid = array();
    279    
    280     if ($input['enable'] == true) {
     317
     318    if ( $input['enable'] == true ) {
    281319        $valid['enable'] = true;
    282320    } else {
    283321        $valid['enable'] = false;
    284322    }
    285    
    286     if ($input['random'] == true) {
     323
     324    if ( $input['random'] == true ) {
    287325        $valid['random'] = true;
    288326    } else {
     
    290328    }
    291329
    292     if ($input['wiggle'] == true) {
     330    if ( $input['wiggle'] == true ) {
    293331        $valid['wiggle'] = true;
    294332    } else {
     
    296334    }
    297335    // number of invaders min 1, max 30
    298     $valid['number_of_invaders'] = min(30, max(1, absint($input['number_of_invaders'])));
     336    $valid['number_of_invaders'] = min( 30, max( 1, absint( $input['number_of_invaders'] ) ) );
    299337    // duration min 250, max 10000
    300     $valid['duration'] = min(10000, max(250, absint($input['duration'])));
     338    $valid['duration'] = min( 10000, max( 250, absint( $input['duration'] ) ) );
    301339    // pause min 0, max 10000
    302     $valid['pause'] = min(10000, max(0, absint($input['pause'])));
    303 
    304     $valid['size'] = intval($input['size']);
    305 
    306     $valid['attack_mode'] = intval($input['attack_mode']);   
    307 
    308     if ($input['use_custom_field'] == 'true') {
     340    $valid['pause'] = min( 10000, max( 0, absint( $input['pause'] ) ) );
     341
     342    $valid['size'] = intval( $input['size'] );
     343
     344    $valid['attack_mode'] = intval( $input['attack_mode'] );
     345
     346    $valid['z_index'] = intval( $input['z_index'] );
     347    $valid['container_element'] = wp_filter_nohtml_kses( $input['container_element'] );
     348
     349    if ( $input['use_custom_field'] == 'true' ) {
    309350        $valid['use_custom_field'] = true;
    310351    } else {
    311352        $valid['use_custom_field'] = false;
    312353    }
    313     if ($input['no_boundry'] == true) {
    314         $valid['no_boundry'] = true;
    315     } else {
    316         $valid['no_boundry'] = false;
    317     }
    318  
    319     $valid['top'] = absint($input['top']);
    320     $valid['bottom'] = absint($input['bottom']);
    321     $valid['left'] = absint($input['left']);
    322     $valid['right'] = absint($input['right']);
     354    if ( $input['boundary'] == true ) {
     355        $valid['boundary'] = true;
     356    } else {
     357        $valid['boundary'] = false;
     358    }
     359
     360    $valid['top'] = absint( $input['top'] );
     361    $valid['bottom'] = absint( $input['bottom'] );
     362    $valid['left'] = absint( $input['left'] );
     363    $valid['right'] = absint( $input['right'] );
     364
    323365
    324366    return $valid;
    325367}
    326368
    327 
    328 
    329369/*
    330  * Generate the invaders javascript based on user settings
     370 * Generate the invaders JavaScript based on user settings
    331371 */
    332372
    333373function jellyfish_invaders_print_script() {
    334374    global $wpdb;
    335     $options = get_option('jellyfish_invaders_options');
     375    $options = get_option( 'jellyfish_invaders_options' );
    336376    $count = 0;
    337     $script = '';
    338377    $small_speed = 2;
    339378    $medium_speed = 1.5;
    340379    $large_speed = 1;
    341  
    342     // check if we are displaying globablly or ONLY on post/page that
     380
     381    // check if we are displaying globally or ONLY on post/page that
    343382    // has jellyfish_invaders custom field set to TRUE
    344     if ($options['use_custom_field'] == true) {
    345         if (is_single() OR is_page()) {
    346             $cv = get_post_meta(get_the_ID(), 'jellyfish_invaders',true);
    347             if ( ($cv != 'true') && ($cv != 'on')){ 
    348                // abort: no custom field
     383    if ( $options['use_custom_field'] == true ) {
     384        if ( is_single() or is_page() ) {
     385            $cv = get_post_meta( get_the_ID(), 'jellyfish_invaders', true );
     386            if ( ( $cv != 'true' ) && ( $cv != 'on' ) ) {
     387                // abort: no custom field
    349388                return;
    350389            }
     
    354393        }
    355394    }
    356    
    357     // first set up variables for things that are applicable to all invaders
    358     if ($options['no_boundry'] == true) {
    359         // free to roam entire page
    360         $top = 0;
    361         $left = 0;
    362         $right ="jQuery(document).width()-jQuery('#invader0').width()";
    363         $bottom = "jQuery(document).height()-jQuery('#invader0').height()";       
    364     } else {
    365         // use boundry settings
    366         $top = $options['top'];
    367         $left = $options['left'];
    368         $right = $options['right'];
    369         $bottom = $options['bottom'];
    370     }
    371    
     395
    372396    // choose class (size of invader depending on settings)
    373397    // as we are acting on sizes here also set up the
    374     // appropiate speed and pause bounce
    375     if ($options['size'] === 1) {
    376           $class='small-invader';
    377           $spd = $small_speed;
    378           $bounce = ', bounce:[1, 55, '. 2000 / $spd . ']';
    379     } elseif ($options['size'] === 2) {
    380           $class='medium-invader';
    381           $spd = $medium_speed;
    382           $bounce = ', bounce:[1, 110, '. 2000 / $spd . ']';
    383     } else {
    384           $class='large-invader';
    385           $spd = $large_speed;
    386           $bounce = ', bounce:[1, 220, '. 2000 / $spd . ']';
    387     }
    388    
     398    // appropriate speed and pause bounce
     399    if ( $options['size'] === 1 ) {
     400        $class='small-invader';
     401        $spd = $small_speed;
     402        $bounce = ', bounce:[1, 55, '. 2000 / $spd . ']';
     403        $width = 55;
     404        $height = 45;
     405    } elseif ( $options['size'] === 2 ) {
     406        $class='medium-invader';
     407        $spd = $medium_speed;
     408        $bounce = ', bounce:[1, 110, '. 2000 / $spd . ']';
     409        $width = 110;
     410        $height = 90;
     411    } else {
     412        $class='large-invader';
     413        $spd = $large_speed;
     414        $bounce = ', bounce:[1, 220, '. 2000 / $spd . ']';
     415        $width = 220;
     416        $height = 180;
     417    }
     418
    389419    // blank the pause bounce if it is not wanted
    390     if ($options['wiggle'] != true) {
     420    if ( $options['wiggle'] != true ) {
    391421        $bounce ='';
    392     }   
    393  
    394     while ($count < $options['number_of_invaders'] ) {
    395         // create js for each invader required, include a bit of random variation
     422    } else {
     423        $width * 2;
     424    }
     425
     426    $top = $options['top'];
     427    $left = $options['left'];
     428    $right = $options['right'];
     429    $bottom = $options['bottom'];
     430    $z_index = $options['z_index'] ? $options['z_index'] : 0 ;
     431    $container = $options['container_element'] ? $options['container_element'] : 'body';
     432
     433    $script = "var invaderContainer = jQuery('$container');";
     434
     435    if ( $options['boundary'] == true ) {
     436        // use boundary settings
     437        $container = 'body';
     438        $script .= "
     439            var invaderContainer = jQuery('$container');
     440            var invaderBoundaryTop = $top;
     441            var invaderBoundaryLeft = $left;
     442            var invaderBoundaryRight = $right - $width;
     443            var invaderBoundaryBottom = $bottom - $height;
     444        ";
     445
     446    } else {
     447        // free to roam entire containing element
     448        $script .= "
     449            var invaderContainer = jQuery('$container');
     450            var invaderBoundaryTop = invaderContainer.offset().top;
     451            var invaderBoundaryLeft = invaderContainer.offset().left;
     452            var invaderBoundaryRight = ( invaderBoundaryLeft + invaderContainer.width() ) - $width;
     453            var invaderBoundaryBottom = ( invaderBoundaryTop + invaderContainer.height() ) - $height;
     454        ";
     455    }
     456
     457    while ( $count < $options['number_of_invaders'] ) {
     458        // create js for each invader required, include a bit of random variation
    396459        // to the duration and pause to make it less uniform if set in settings
    397         if ($options['random'] == true) {
    398             $duration = max(0, ($options['duration']+(($options['duration']/100) * rand(-50, 50))));
    399             $pause = max(0, ($options['pause']+(($options['pause']/100) * rand(-50, 50))));           
     460        if ( $options['random'] == true ) {
     461            $duration = max( 0, ( $options['duration']+( ( $options['duration']/100 ) * rand( -50, 50 ) ) ) );
     462            $pause = max( 0, ( $options['pause']+( ( $options['pause']/100 ) * rand( -50, 50 ) ) ) );
    400463        } else {
    401464            $duration = $options['duration'];
    402             $pause = $options['pause'];                     
     465            $pause = $options['pause'];
    403466        }
    404         $script.="var invaderDiv = jQuery(document.createElement('div')).attr('id','invader$count').addClass('$class').appendTo('body');\n";
    405         $script .= "jQuery('#invader$count').sprite({fps: $spd, no_of_frames: 2 $bounce}).spRandom({top: $top, left: $left, right: $right, bottom: $bottom, speed: $duration, pause: $pause}).active().activeOnClick().bounce;\n";       
     467        $script.="
     468            var jellyfishInvaderDiv$count = jQuery('<div>', { id: 'jellyfishInvader$count', class: '$class'})
     469                .css('z-index', $z_index)
     470                .appendTo('$container')
     471                .sprite({
     472                    fps: $spd,
     473                    no_of_frames: 2
     474                    $bounce
     475                })
     476                .spRandom({
     477                    top: invaderBoundaryTop,
     478                    left: invaderBoundaryLeft,
     479                    right: invaderBoundaryRight,
     480                    bottom: invaderBoundaryBottom,
     481                    speed: $duration,
     482                    pause: $pause
     483                })
     484                .active()
     485                .activeOnClick()
     486                .bounce;
     487            \n";
    406488        $count ++;
    407489    }
    408490    echo "<script>jQuery(document).ready(function() {";
    409491    echo $script;
     492
    410493    // add a ftytotap even if attack mode is set, either just first invader or all elements with
    411494    // invader classes (hopefully these are just invaders!)
    412     if ($options['attack_mode'] === 3) {
    413         echo "jQuery('html').flyToTap({el_to_move: '.".$class."', ms: 500, do_once: false});";
    414     } elseif ($options['attack_mode'] === 2) {
    415                 echo "jQuery('html').flyToTap({el_to_move: '#invader0', ms: 500, do_once: false});";
    416     }
     495    if ( $options['attack_mode'] === 3 ) {
     496        echo "jQuery('$container').flyToTap({el_to_move: '.".$class."', ms: 500, do_once: false});";
     497    } elseif ( $options['attack_mode'] === 2 ) {
     498        echo "jQuery('$container').flyToTap({el_to_move: '#jellyfishInvader0', ms: 500, do_once: false});";
     499    }
     500
    417501    echo "});</script>";
    418502}
  • jellyfish-invaders/trunk/readme.txt

    r822235 r1005532  
    33Author URI: http://strawberryjellyfish.com/
    44Donate link: http://strawberryjellyfish.com/donate/
    5 Plugin URI: http://strawberryjellyfish.com/wordpress-plugin-jellyfish-invaders/
     5Plugin URI: http://strawberryjellyfish.com/wordpress-plugins/jellyfish-invaders/
    66Tags: retro, space invaders, 8bit, animation, visual effect, animated aliens, sci fi, gaming,
    77Requires at least: 3.0
    8 Tested up to: 3.8
    9 Stable tag: 0.8.1
     8Tested up to: 4.0
     9Stable tag: 0.8
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1212
    13 Adds animated flying retro space invaders to your blog. You can configure,
    14 number, size, behaviour and where they appear.
     13Add pixelated pets to your site in the form of funky animated retro
     14space invaders.
    1515
    1616== Description ==
    1717
    18 This plugin for WordPress adds a number of retro space invaders to your blog pages
    19 that will randomly fly around, and if you choose home in on any mouse clicks.
     18Your new pixelated pals will randomly fly around, and if you choose, home in
     19on any mouse clicks. The glowing retro 8bit scan-line effect space invaders
     20work on most backgrounds but obviously are more suited to a dark theme. It's
     21easy to configure the number, size, behaviour and where the invaders appear
     22through the comprehensive admin control panel.
    2023
    21 You can choose the number, size, speed, and behaviour of the space invaders as
    22 well as limit them to a specific area of your pages, a single post, or the entire
    23 blog.
     24Demo and more information at the plugin homepage:
    2425
    25 Great glowing retro 8bit scanline effect space invaders work on most backgrounds
    26 but obviously are more suited to a dark theme.
     26http://strawberryjellyfish/wordpress-plugins/jellyfish-invaders
    2727
    28 Demo
     28= Configuring your Invaders =
    2929
    30 You can see them in action on the plugin page at
    31 http://strawberryjellyfish.com/wordpress-plugin-jellyfish-invaders/
     30A new settings page will be added to your Admin Appearance section, where you
     31can change the look and behaviour of your new binary buddies. Here's an
     32overview of the available settings:
    3233
    33 This plugin uses the excellent Spritely library for jQuery. Read more about
    34 Spritely at http://www.spritely.net/
     34* **Enable Invaders** Turn the invaders off and on. A quick way to
     35temporarily disable the invaders without deactivating the plugin.
    3536
     37* **Where to show** you can choose either everywhere OR only on individual
     38posts or pages. You can use this second option to just show them on your home
     39page or a single post for example.
    3640
    37 ==Usage==
     41* **The invaders will look out for a custom field called "jellyfish_invaders"
     42on any post or page. If they find one and it has a value of 'true' or 'on'
     43they will populate the page.
    3844
    39 The plugin will show some invaders on every page of your blog when first installed.
    40 To change this to your liking you will find a setting page in the Appearance menu
    41 of your WordPress admin, Here you can configure your invaders.
     45* **Number of Invaders** how many individual space invaders you want, keep
     46this number quite low to avoid slowing down your page too much
    4247
    43 General Settings
     48* **Invader Size** size of the invaders
    4449
    45 * Enable Invaders - If you want to turn Invaders on or off use this
     50* **Fly Time** how long the invaders fly around before pausing in
     51milliseconds (1000 = 1 second)
    4652
    47 * Where to show - you can choose either everywhere OR only on individual posts
    48 or pages that contain the custom field "jellyfish_invaders". You can use this
    49 second option to just show them on your home page or a single post for example.
    50 Simply add the custom field "jellyfish_invaders" with a value of "true" or "on"
    51 to any post you want them to appear.
     53* **Pause Time** How long the invaders Pause (or wiggle see below) for
     54between flying cycles.
    5255
    53 Boundries
     56* **Random** adds some variation to the time settings so each invader
     57acts a little differently.
    5458
    55 By default the invaders will be free to roam randomly around the entire document.
    56 If you want to restrict them to an area for example a header, sidebar or blank
    57 area on your page to avoid distracting from the main content simply uncheck the
    58 "Ignore Boundries" checkbox and fill in the top, left, right and bottom pixel
    59 values of your invisible invader electric fence.
     59* **Wiggle** Instead of pausing the invaders will do a missile evasive
     60wiggle.
    6061
     62* **Attack Mode** None, One or All of the invaders will home in on any
     63mouse clicks.
    6164
     65By default the invaders will be free to roam randomly around the entire page,
     66but there are a couple of methods to confine them to specific areas if you wish.
     67
     68* **Containing Element** the invaders will only roam within the element set
     69here, normally that's body (the whole page) but you may enter the id of an
     70element on the page to confine them to a specific area. You can see this in
     71effect right here where the invaders have been limited to the section at the
     72top of the page.
     73
     74* **Z-Index** If you'd like the invaders to hide behind certain layers on
     75your page you can set an appropriate z-index here, obviously this setting it
     76very dependant on the structure of your WordPress theme.
     77
     78* **Use Electric Fence** Check this option and use the top, left, right
     79and bottom options to define a virtual fence that will contain the invaders.
     80The values you enter represent pixels position on the entire document. Note,
     81this option will override any custom setting for Containing Element.
    6282
    6383== Installation ==
    6484
    65 Extract the zip file and just drop the contents in the wp-content/plugins/
    66 directory of your WordPress installation and then activate the Plugin from
    67 Plugins page. Visit your blog and marvel at the spectacle, then go to the
    68 Jellyfish Invaders settings page in the Appearance menu of your WordPress
    69 admin to play with the settings.
     85Either install and activate the plugin via your WordPress Admin
    7086
    71 == Frequently Asked Questions ==
     87Or
    7288
    73 None yet
     89Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from
     90Plugins page.
     91
     92When first installed the Jellyfish Invaders plugin will show some invaders on
     93every page of your blog. You can easily change this to your liking by visiting
     94the setting page, you will find a link to the settings page in the Appearance
     95menu of your WordPress admin.
     96
     97== Frequently Asked Questions ==
     98
     99== Screenshots ==
    74100
    75101== Changelog ==
    76102
    77 * 0.8.1 tweaked admin for WordPress 3.8
    78 * 0.75  changed the way scripts are queued to ensure javascript is only included
    79 when invaders are actually needed.       
    80 * 0.6   initial release
     103= 0.8 =
     104* Tested up to WordPress 4.0
     105* Added Containing Element option: Confine invaders to a specific page element
     106* Added Z-index support: Configure invaders z-index for layering in document
     107* Updated Admin screen
     108* Updated Spritely version
     109
     110= 0.7 =
     111* changed the way scripts are queued to ensure JavaScript is only included when invaders are actually needed.
     112
     113= 0.6 =
     114* Initial release
     115
    81116
    82117== Upgrade Notice ==
    83118
    84 == Screenshots ==
     119There should be no issues upgrading from a previous version. Visit the plugin
     120settings page in Admin > Appearance > jellyfish Invaders to configure new
     121options.
Note: See TracChangeset for help on using the changeset viewer.