Plugin Directory

Changeset 1243970


Ignore:
Timestamp:
09/12/2015 10:34:07 AM (10 years ago)
Author:
rclick
Message:

started template code

Location:
i-am-human/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • i-am-human/trunk/css/grid_styles.css

    r930241 r1243970  
    1212
    1313.grid_row {
    14     height: 3.65%;
    1514    width: 100%;
    1615    display: table-row;
     
    4746    padding-left: 10px;
    4847}
    49 
    50 /**
    51 * Grid container used in the front end
    52 */
    53 .iamhuman_grid {
    54     width: 250px;
    55     height: 250px; 
    56 }
  • i-am-human/trunk/iamhuman.php

    r930311 r1243970  
    66  filtering (otherwise known as captcha), that can be imbeded into forms.
    77  Author: Benjamin Leov
    8   Version: 1.0
     8  Version: 1.1
    99  Author URI: programminglinuxblog.blogspot.com
    1010  License: http://www.gnu.org/licenses/gpl-2.0.html
     
    6161            "guide = '" . get_option('question_colour_two_string') . "';" .
    6262           
    63             "create_grid(\"#iamhuman_grid\", 22);
     63            "create_grid(\"#iamhuman_grid\", " . get_option('grid_size') .");
    6464               
    6565            highlight_list(\"#iamhuman_grid\", \"colour_one\", foreground);
     
    196196
    197197
    198 function iamhuman_validate_comment() {
    199    
     198function iamhuman_validate_comment($comment_data) {
     199
    200200    if(iamhuman_is_enabled()) {
    201201       
     
    205205       
    206206            if(empty($_POST['iamhuman_answer'])) {
    207                 wp_die( get_option("incorrect_attempt_message")); 
     207               wp_die( get_option("incorrect_attempt_message")); 
    208208            } else {
    209209
     
    213213                    wp_die( get_option("incorrect_attempt_message"));
    214214                }
    215 
    216215            }
    217216        }
     217
     218    return $comment_data;
     219
     220    } else {
     221    // plugin not enabled
     222    return $comment_data;
    218223    }
    219224}
  • i-am-human/trunk/iamhuman_constants.php

    r930241 r1243970  
    22
    33class IamHumanConstants {
     4
    45    static $IAMHUMAN_SETTINGS_ID = "iamhuman-settings";
    56    static $IAMHUMAN_TEXT_DOMAIN = "i-am-human";
    6    
     7    static $IAMHUMAN_AJAX_ACTION_SET_TEMPLATE = "iamhuman_set_template";
     8
     9    /**
     10     * template directory
     11     *
     12     * @var string
     13     */
     14    static $IAMHUMAN_TEMPLATE_FOLDER = "templates/";
     15
     16    /**
     17     * Options
     18     *
     19     * When adding a new option, remember to add it to the all options
     20     * array below.
     21     *
     22     * @var string
     23     */
     24    const IAMHUMAN_OPTION_COLOUR_ONE = "colour_one";
     25    const IAMHUMAN_OPTION_COLOUR_TWO = "colour_two";
     26    const IAMHUMAN_OPTION_COLOUR_HOVER = "colour_hover";
     27    const IAMHUMAN_OPTION_GRID_SIZE = "grid_size";
     28    const IAMHUMAN_OPTION_BACKGROUND_COLOUR = "background_colour";
     29    const IAMHUMAN_OPTION_DESCRIPTION_TITLE = "description_title";
     30    const IAMHUMAN_OPTION_DESCRIPTION_TEXT = "description_text";
     31    const IAMHUMAN_OPTION_INCORRECT_ATTEMPT_MESSAGE = "incorrect_attempt_message";
     32    const IAMHUMAN_OPTION_QUESTION_COLOUR_ONE_STRING = "question_colour_one_string";
     33    const IAMHUMAN_OPTION_QUESTION_COLOUR_TWO_STRING = "question_colour_two_string";
     34    const IAMHUMAN_OPTION_ANSWER_COLOUR_ONE_STRING = "answer_colour_one_string";
     35    const IAMHUMAN_OPTION_ANSWER_COLOUR_TWO_STRING = "answer_colour_two_string";
     36    const IAMHUMAN_OPTION_ENABLE_POST_COMMENTS = "enable_post_comments";
     37
     38    /**
     39     * All options
     40     *
     41     * @var array(string)
     42     */
     43    static $IAMHUMAN_OPTIONS = array(
     44        IAMHUMAN_OPTION_COLOUR_ONE,
     45        IAMHUMAN_OPTION_COLOUR_TWO,
     46        IAMHUMAN_OPTION_COLOUR_HOVER,
     47        IAMHUMAN_OPTION_GRID_SIZE,
     48        IAMHUMAN_OPTION_BACKGROUND_COLOUR,
     49        IAMHUMAN_OPTION_DESCRIPTION_TITLE,
     50        IAMHUMAN_OPTION_DESCRIPTION_TEXT,
     51        IAMHUMAN_OPTION_INCORRECT_ATTEMPT_MESSAGE,
     52        IAMHUMAN_OPTION_QUESTION_COLOUR_ONE_STRING,
     53        IAMHUMAN_OPTION_QUESTION_COLOUR_TWO_STRING,
     54        IAMHUMAN_OPTION_ANSWER_COLOUR_ONE_STRING,
     55        IAMHUMAN_OPTION_ANSWER_COLOUR_TWO_STRING,
     56        IAMHUMAN_OPTION_ENABLE_POST_COMMENTS,
     57    );
     58
    759}
    860
  • i-am-human/trunk/iamhuman_options.php

    r930241 r1243970  
    55
    66    // colours to display on the page
    7     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "colour_one");
    8     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "colour_two");
    9     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "colour_hover");
    10 
    11     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "background_colour");
    12    
    13     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "description_title");
    14     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "description_text");
    15     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "incorrect_attempt_message");
     7    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_COLOUR_ONE);
     8    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_COLOUR_TWO);
     9    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_COLOUR_HOVER);
     10
     11    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_GRID_SIZE);
     12
     13    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_BACKGROUND_COLOUR);
     14
     15    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_DESCRIPTION_TITLE);
     16    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_DESCRIPTION_TEXT);
     17    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_INCORRECT_ATTEMPT_MESSAGE);
    1618
    1719    // question colour strings
    18     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "question_colour_one_string");
    19     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "question_colour_two_string");
     20    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_QUESTION_COLOUR_ONE_STRING);
     21    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_QUESTION_COLOUR_TWO_STRING);
    2022
    2123    // answer colour strings
    22     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "answer_colour_one_string");
    23     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "answer_colour_two_string");
    24 
    25     register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, "enable_post_comments");
     24    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_ANSWER_COLOUR_ONE_STRING);
     25    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_ANSWER_COLOUR_TWO_STRING);
     26
     27    register_setting(IamHumanConstants::$IAMHUMAN_SETTINGS_ID, IamHumanConstants::IAMHUMAN_OPTION_ENABLE_POST_COMMENTS);
    2628}
    2729
     
    4951    <div class="wrap">
    5052
     53        <form method="post" action="options.php" id="iamhuman_template_form">
     54            <input type="hidden" value="template_select" id="setting_type" name="setting_type"/>
     55            <?php
     56            // look for templates
     57            $template_files = iamhuman_get_templates();
     58
     59            if (sizeof($template_files) > 0) {
     60
     61                echo "<h3>" . __("Templates", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>";
     62
     63                echo "<p>" . __("You have some templates installed! Choose one in the below dropdown box, or make your own grids "
     64                        . "in the section below.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     65
     66                echo "</p>";
     67                echo "<p><strong>";
     68
     69                echo __("Note that choosing a template will overwrite any changes made manually.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     70
     71                echo "</strong></p>";
     72
     73                echo "<select id='template_select'>";
     74
     75                foreach ($template_files as $template_file) {
     76                    $contents = file_get_contents($template_file);
     77                    $json = json_decode($contents);
     78                    echo "<option value='" . $json->id . "'>" . $json->template_name . "</option>";
     79                }
     80
     81                echo "</select>";
     82        ?>
     83
     84                <p class="submit">
     85                    <input id="apply_template_submit"
     86                        class="button button-primary"
     87                        type="submit"
     88                        value="<?php echo __("Apply Template", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN); ?>" />
     89
     90    <?php
     91            }
     92    ?>
     93
     94        </form>
     95
     96        <script>
     97
     98            jQuery(document).ready(function($) {
     99
     100                $("#apply_template_submit").click(function(event) {
     101                    event.preventDefault();
     102
     103                    if (confirm('Are you sure you wish to apply this template and overwrite your changes?')) {
     104
     105                        template_id = $("#template_select").val();
     106
     107                        var data = {
     108                            'action': '<?php echo IamHumanConstants::$IAMHUMAN_AJAX_ACTION_SET_TEMPLATE; ?>',
     109                            'template_id': template_id
     110                        };
     111
     112                        $.post(ajaxurl, data, function(response) {
     113
     114                            if (response === '0') {
     115                                alert("Unfortunately the server had a problem with your request.")
     116                            } else {
     117                                alert(response);
     118                               // document.location.reload(true);
     119                            }
     120                        });
     121                    }
     122                });
     123
     124            });
     125        </script>
     126
    51127        <form method="post" action="options.php" id="iamhuman_options_form">
    52            
     128
    53129            <?php settings_fields(IamHumanConstants::$IAMHUMAN_SETTINGS_ID); ?>
    54130            <?php do_settings_sections(IamHumanConstants::$IAMHUMAN_SETTINGS_ID); ?>
    55            
     131
    56132            <table class="form-table">
    57133                <tr valign="top">
    58134                    <th scope="row">Enable for post comments</th>
    59                         <?php
    60                         $enabled = filter_var(filter_var(get_option('enable_post_comments'), FILTER_VALIDATE_BOOLEAN));
    61                         if ($enabled) {
    62                             $value = "checked='checked'";
    63                         } else {
    64                             $value = "";
    65                         }
    66                         ?>                                         
     135                    <?php
     136                    $enabled = filter_var(filter_var(get_option(IamHumanConstants::IAMHUMAN_OPTION_ENABLE_POST_COMMENTS), FILTER_VALIDATE_BOOLEAN));
     137                    if ($enabled) {
     138                        $value = "checked='checked'";
     139                    } else {
     140                        $value = "";
     141                    }
     142                    ?>
    67143                    <td><input type="checkbox" name="enable_post_comments" <?php echo $value; ?> value="true" /></td>
    68144                </tr>
    69145            </table>
    70146
    71         <?php echo "<h3>" . __("Dialog Box Options", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>
    72            
    73             <p>
    74             <?php echo __("Select a title for the dialog box, as well as some descriptive text that will be displayed near the grid so the user"
    75                     . " knows what they should colour in.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN); ?>
     147            <?php echo "<h3>" . __("Dialog Box Options", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>
     148
     149            <p>
     150                <?php
     151                echo __("Select a title for the dialog box, as well as some descriptive text that will be displayed near the grid so the user"
     152                        . " knows what they should colour in.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     153                ?>
    76154            </p>
    77155
    78156            <table class="form-table">
    79               <tr valign="top">
     157                <tr valign="top">
    80158                    <th scope="row"><?php echo __('Dialog title', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    81                     <td><input name="description_title" value="<?php echo get_option('description_title'); ?>" /></td>
     159                    <td><input name="description_title" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_DESCRIPTION_TITLE); ?>" /></td>
    82160                </tr>
    83161                <tr valign="top">
    84162                    <th scope="row"><?php echo __('Description Text', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    85                     <td><textarea name="description_text"><?php echo get_option('description_text'); ?></textarea></td>
     163                    <td><textarea name="description_text"><?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_DESCRIPTION_TEXT); ?></textarea></td>
    86164                </tr>
    87165                <tr valign="top">
    88166                    <th scope="row"><?php echo __('Incorrect Attempt Message', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    89                     <td><textarea name="incorrect_attempt_message"><?php echo get_option('incorrect_attempt_message'); ?></textarea></td>
    90                 </tr>
     167                    <td><textarea name="incorrect_attempt_message"><?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_INCORRECT_ATTEMPT_MESSAGE); ?></textarea></td>
     168                </tr>
     169
     170                <tr valign="top">
     171                    <td  colspan="2">
     172
     173                        <p>
     174                            <strong>
     175                                <?php echo __("WARNING: Changing the grid size will likely ruin your picture. Make sure to set it to the size you want
     176                            before you start!"); ?>
     177                            </strong>
     178                        </p>
     179                    </td>
     180                </tr>
     181                <tr valign="top">
     182                    <th scope="row"><?php echo __('Grid Size', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
     183                    <td><input name="grid_size" type="number" value="<?php echo iamhuman_get_grid_size_setting(); ?>" /></td>
     184                </tr>
    91185            </table>
    92186
    93     <?php echo "<h3>" . __("Colours", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>
    94 
    95              <p>
    96                 <?php echo __("Select the colours that will be used in the grid. Note that colour one is the only colour users will be able to select."
    97                         , IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN); ?>
    98              </p>
     187            <?php echo "<h3>" . __("Colours", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>
     188
     189            <p>
     190                <?php
     191                echo __("Select the colours that will be used in the grid. Note that colour one is the only colour users will be able to select."
     192                        , IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     193                ?>
     194            </p>
    99195
    100196            <table class="form-table">
    101197                <tr valign="top">
    102198                    <th scope="row"><?php echo __('Colour one', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    103                     <td><input type="text" class='colour_field' id="colour_one" name="colour_one" value="<?php echo get_option('colour_one'); ?>" /></td>
     199                    <td><input type="text" class='colour_field' id="colour_one" name="colour_one" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_COLOUR_ONE); ?>" /></td>
    104200                </tr>
    105201                <tr valign="top">
    106202                    <th scope="row"><?php echo __('Colour two', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    107                     <td><input type="text" class='colour_field' id="colour_two" name="colour_two" value="<?php echo get_option('colour_two'); ?>" /></td>
     203                    <td><input type="text" class='colour_field' id="colour_two" name="colour_two" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_COLOUR_TWO); ?>" /></td>
    108204                </tr>
    109205                <tr valign="top">
    110206                    <th scope="row"><?php echo __('Hover colour', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    111                     <td><input type="text" class='colour_field' id="colour_hover" name="colour_hover" value="<?php echo get_option('colour_hover'); ?>" /></td>
     207                    <td><input type="text" class='colour_field' id="colour_hover" name="colour_hover" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_COLOUR_HOVER); ?>" /></td>
    112208                </tr>
    113209                <tr valign="top">
    114210                    <th scope="row"><?php echo __('Background colour', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    115                     <td><input type="text" class='colour_field' id="background_colour" name="background_colour" value="<?php echo get_option('background_colour'); ?>" /></td>
     211                    <td><input type="text" class='colour_field' id="background_colour" name="background_colour" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_BACKGROUND_COLOUR); ?>" /></td>
    116212                </tr>
    117213            </table>   
    118214
    119     <?php echo "<h3>" . __("Question Image", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>
    120 
    121             <p>
    122     <?php
    123     echo __("Build the image you would like to be displayed initally below by clicking on the grid. Click once for the first colour,"
    124             . "twice for the second colour, and a third time to reset to the background colour.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
    125     ?>
     215            <?php echo "<h3>" . __("Question Image", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>
     216
     217            <p>
     218                <?php
     219                echo __("Build the image you would like to be displayed initally below by clicking on the grid. Click once for the first colour,"
     220                        . "twice for the second colour, and a third time to reset to the background colour.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     221                ?>
    126222            </p>   
    127223
    128224            <p>
    129     <?php
    130     echo __("Note that the user will only be able to specify colour one, not colour two, to complete the image. Nor will they be able to "
    131             . "modify any cells that are set to colour two.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
    132     ?>
     225                <?php
     226                echo __("Note that the user will only be able to specify colour one, not colour two, to complete the image. Nor will they be able to "
     227                        . "modify any cells that are set to colour two.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     228                ?>
    133229            </p>
    134230
     
    138234            <script>
    139235                jQuery(function($) {
    140                     colour_one_string = "<?php echo get_option('question_colour_one_string') ?>";
    141                     colour_two_string = "<?php echo get_option('question_colour_two_string') ?>";
     236                    colour_one_string = "<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_QUESTION_COLOUR_ONE_STRING) ?>";
     237                    colour_two_string = "<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_QUESTION_COLOUR_TWO_STRING) ?>";
    142238
    143239                    // setup the custom styles
    144                     $('html > head').append($('<style> .colour_bg { background: <?php echo get_option('background_colour'); ?>; }</style>'));
    145                     $('html > head').append($('<style> .colour_one { background: <?php echo get_option('colour_one'); ?>; }</style>'));
    146                     $('html > head').append($('<style> .colour_two { background: <?php echo get_option('colour_two'); ?>; }</style>'));
    147                     $(".grid_cell").css('background-color', '<?php echo get_option('background_colour') ?>');
    148 
    149                     create_grid("#iamhuman_grid_question", 22);
     240                    $('html > head').append($('<style> .colour_bg { background: <?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_BACKGROUND_COLOUR); ?>; }</style>'));
     241                    $('html > head').append($('<style> .colour_one { background: <?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_COLOUR_ONE); ?>; }</style>'));
     242                    $('html > head').append($('<style> .colour_two { background: <?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_COLOUR_TWO); ?>; }</style>'));
     243                    $(".grid_cell").css('background-color', '<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_BACKGROUND_COLOUR) ?>');
     244
     245                    create_grid("#iamhuman_grid_question", <?php echo iamhuman_get_grid_size_setting(); ?>);
    150246
    151247                    highlight_list("#iamhuman_grid_question", "colour_one", colour_one_string);
     
    171267                <tr valign="top">
    172268                    <th scope="row"><?php echo __('question_colour_one_string', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    173                     <td><input type="text" id="question_colour_one_string" name="question_colour_one_string" value="<?php echo get_option('question_colour_one_string'); ?>" /></td>
     269                    <td><input type="text" id="question_colour_one_string" name="question_colour_one_string" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_QUESTION_COLOUR_ONE_STRING); ?>" /></td>
    174270                </tr>
    175271                <tr valign="top">
    176272                    <th scope="row"><?php echo __('question_colour_two_string', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    177                     <td><input type="text" id="question_colour_two_string" name="question_colour_two_string" value="<?php echo get_option('question_colour_two_string'); ?>" /></td>
     273                    <td><input type="text" id="question_colour_two_string" name="question_colour_two_string" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_QUESTION_COLOUR_TWO_STRING); ?>" /></td>
    178274                </tr>
    179275                <tr valign="top">
    180276                    <th scope="row"><?php echo __('answer_colour_one_string', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    181                     <td><input type="text" id="answer_colour_one_string" name="answer_colour_one_string" value="<?php echo get_option('answer_colour_one_string'); ?>" /></td>
     277                    <td><input type="text" id="answer_colour_one_string" name="answer_colour_one_string" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_ANSWER_COLOUR_ONE_STRING); ?>" /></td>
    182278                </tr>
    183279                <tr valign="top">
    184280                    <th scope="row"><?php echo __('answer_colour_two_string', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?></th>
    185                     <td><input type="text" id="answer_colour_two_string" name="answer_colour_two_string" value="<?php echo get_option('answer_colour_two_string'); ?>" /></td>
     281                    <td><input type="text" id="answer_colour_two_string" name="answer_colour_two_string" value="<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_ANSWER_COLOUR_TWO_STRING); ?>" /></td>
    186282                </tr>
    187283            </table>
    188284
    189     <?php echo "<h3>" . __("Answer Image", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>
    190             <p>
    191             <?php
    192             echo __("Build the answer image below, that the user must match in order to pass the test succesfully.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
    193             ?>
     285            <?php echo "<h3>" . __("Answer Image", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>
     286            <p>
     287                <?php
     288                echo __("Build the answer image below, that the user must match in order to pass the test succesfully.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     289                ?>
    194290            </p>   
    195291
    196292            <p>
    197     <?php echo __('Click the copy button to copy the question image to the answer image.', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) ?>
     293                <?php echo __('Click the copy button to copy the question image to the answer image.', IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN); ?>
    198294                <input type="button" id="copy_to_answer" value="Copy"/>
    199295            </p>
     
    226322                jQuery(function($) {
    227323
    228                     create_grid("#iamhuman_grid_answer", 22);
    229 
    230                     answer_colour_one_string = "<?php echo get_option('answer_colour_one_string') ?>";
    231                     answer_colour_two_string = "<?php echo get_option('answer_colour_two_string') ?>";
     324                    create_grid("#iamhuman_grid_answer", <?php echo iamhuman_get_grid_size_setting(); ?>);
     325
     326                    answer_colour_one_string = "<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_ANSWER_COLOUR_ONE_STRING);?>";
     327                    answer_colour_two_string = "<?php echo get_option(IamHumanConstants::IAMHUMAN_OPTION_ANSWER_COLOUR_TWO_STRING); ?>";
    232328
    233329                    highlight_list("#iamhuman_grid_answer", "colour_one", answer_colour_one_string);
     
    248344            </script>
    249345
    250     <?php submit_button(); ?>
     346            <?php submit_button(); ?>
    251347        </form>
    252348    </div>
     
    259355    add_options_page(
    260356            __('I am human options', 'i-am-human'), __('I am human options', 'i-am-human'), 'manage_options', 'i-am-human-options', 'iamhuman_options_page');
    261 } ?>
     357}
     358
     359/**
     360 * Gets the grid size, with the default option set.
     361 *
     362 * @return int
     363 */
     364function iamhuman_get_grid_size_setting() {
     365    return get_option(IamHumanConstants::IAMHUMAN_OPTION_GRID_SIZE, 22);
     366}
     367
     368/**
     369 * Applys the template ajax callback
     370 *
     371 * @global type $wpdb
     372 */
     373function iamhuman_ajax_set_template_callback() {
     374//    global $wpdb; // this is how you get access to the database
     375//    // TODO: APPLY THE TEMPLATE!
     376
     377    $template_id = $_POST['template_id'];
     378
     379    $response = new stdClass();
     380   
     381    if ($template_id) {
     382
     383        $template = iamhuman_get_template($template_id);
     384
     385        if ($template) {
     386            iamhuman_apply_template($template);
     387            $response->success = true;
     388        } else {
     389            $response->success = false;
     390            $response->messsage = __("No template matched that id", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     391        }
     392    } else {
     393        $response->success = false;
     394        $response->messsage = __("No template matched was specifie.", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN);
     395    }
     396
     397    echo json_encode($response);
     398
     399    die();
     400}
     401
     402add_action('wp_ajax_' . IamHumanConstants::$IAMHUMAN_AJAX_ACTION_SET_TEMPLATE, 'iamhuman_ajax_set_template_callback');
     403
     404/**
     405 * Returns all templates.
     406 *
     407 * @return type
     408 */
     409function iamhuman_get_templates() {
     410    return glob(plugin_dir_path(__FILE__) . IamHumanConstants::$IAMHUMAN_TEMPLATE_FOLDER . "*.tpl");
     411}
     412
     413/**
     414 * Returns a template with the given id if it exists, otherwise returns null.
     415 *
     416 * @param type $template_id
     417 * @return null
     418 */
     419function iamhuman_get_template($template_id) {
     420    $template_files = iamhuman_get_templates();
     421
     422    if (sizeof($template_files) > 0) {
     423        foreach ($template_files as $template_file) {
     424            $contents = file_get_contents($template_file);
     425            $json = json_decode($contents);
     426
     427            if ($json->id === $template_id) {
     428                return $json;
     429            }
     430        }
     431    }
     432
     433    return null;
     434}
     435
     436/**
     437 * Applies the given template
     438 *
     439 * @param type $template
     440 */
     441function iamhuman_apply_template($template) {
     442    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_COLOUR_ONE);
     443    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_COLOUR_TWO);
     444    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_COLOUR_HOVER);
     445    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_GRID_SIZE);
     446    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_BACKGROUND_COLOUR);
     447    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_DESCRIPTION_TITLE);
     448    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_DESCRIPTION_TEXT);
     449    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_INCORRECT_ATTEMPT_MESSAGE);
     450    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_QUESTION_COLOUR_ONE_STRING);
     451    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_QUESTION_COLOUR_TWO_STRING);
     452    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_ANSWER_COLOUR_ONE_STRING);
     453    iamhuman_update_template_option($template, IamHumanConstants::IAMHUMAN_OPTION_ANSWER_COLOUR_TWO_STRING);
     454}
     455
     456function iamhuman_update_template_option($template, $option_id) {
     457    if($template->{$option_id}) {
     458        update_option($option_id, $template->{$option_id});
     459    }
     460}
     461
     462
     463?>
  • i-am-human/trunk/js/iamhuman.js

    r930241 r1243970  
    8484        grid_element.append(new_row);
    8585    }
    86 
     86   
     87    grid_element.width(10 * grid_length);
     88    grid_element.height(10 * grid_length);
     89   
     90    // 22 ->  250px; (11)
     91    //height: 250px; 
     92 
    8793    return grid_element;
    8894}
     
    112118}
    113119
     120/**
     121 * Removes all styles from all cells.
     122 *
     123 * @param string grid_selector
     124 * @returns
     125 */
    114126function clear_grid(grid_selector) {
    115127    jQuery(grid_selector + " .grid_cell").each(function() {
     
    118130        jQuery(this).addClass("colour_bg");
    119131    });
     132}
     133
     134function delete_grid(grid_selector) {
     135    jQuery(grid_selector).empty();
    120136}
    121137
Note: See TracChangeset for help on using the changeset viewer.