Changeset 1243970
- Timestamp:
- 09/12/2015 10:34:07 AM (10 years ago)
- Location:
- i-am-human/trunk
- Files:
-
- 5 edited
-
css/grid_styles.css (modified) (2 diffs)
-
iamhuman.php (modified) (5 diffs)
-
iamhuman_constants.php (modified) (1 diff)
-
iamhuman_options.php (modified) (7 diffs)
-
js/iamhuman.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
i-am-human/trunk/css/grid_styles.css
r930241 r1243970 12 12 13 13 .grid_row { 14 height: 3.65%;15 14 width: 100%; 16 15 display: table-row; … … 47 46 padding-left: 10px; 48 47 } 49 50 /**51 * Grid container used in the front end52 */53 .iamhuman_grid {54 width: 250px;55 height: 250px;56 } -
i-am-human/trunk/iamhuman.php
r930311 r1243970 6 6 filtering (otherwise known as captcha), that can be imbeded into forms. 7 7 Author: Benjamin Leov 8 Version: 1. 08 Version: 1.1 9 9 Author URI: programminglinuxblog.blogspot.com 10 10 License: http://www.gnu.org/licenses/gpl-2.0.html … … 61 61 "guide = '" . get_option('question_colour_two_string') . "';" . 62 62 63 "create_grid(\"#iamhuman_grid\", 22);63 "create_grid(\"#iamhuman_grid\", " . get_option('grid_size') ."); 64 64 65 65 highlight_list(\"#iamhuman_grid\", \"colour_one\", foreground); … … 196 196 197 197 198 function iamhuman_validate_comment( ) {199 198 function iamhuman_validate_comment($comment_data) { 199 200 200 if(iamhuman_is_enabled()) { 201 201 … … 205 205 206 206 if(empty($_POST['iamhuman_answer'])) { 207 wp_die( get_option("incorrect_attempt_message"));207 wp_die( get_option("incorrect_attempt_message")); 208 208 } else { 209 209 … … 213 213 wp_die( get_option("incorrect_attempt_message")); 214 214 } 215 216 215 } 217 216 } 217 218 return $comment_data; 219 220 } else { 221 // plugin not enabled 222 return $comment_data; 218 223 } 219 224 } -
i-am-human/trunk/iamhuman_constants.php
r930241 r1243970 2 2 3 3 class IamHumanConstants { 4 4 5 static $IAMHUMAN_SETTINGS_ID = "iamhuman-settings"; 5 6 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 7 59 } 8 60 -
i-am-human/trunk/iamhuman_options.php
r930241 r1243970 5 5 6 6 // 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); 16 18 17 19 // 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); 20 22 21 23 // 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); 26 28 } 27 29 … … 49 51 <div class="wrap"> 50 52 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 51 127 <form method="post" action="options.php" id="iamhuman_options_form"> 52 128 53 129 <?php settings_fields(IamHumanConstants::$IAMHUMAN_SETTINGS_ID); ?> 54 130 <?php do_settings_sections(IamHumanConstants::$IAMHUMAN_SETTINGS_ID); ?> 55 131 56 132 <table class="form-table"> 57 133 <tr valign="top"> 58 134 <th scope="row">Enable for post comments</th> 59 <?php60 $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 ?> 67 143 <td><input type="checkbox" name="enable_post_comments" <?php echo $value; ?> value="true" /></td> 68 144 </tr> 69 145 </table> 70 146 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 ?> 76 154 </p> 77 155 78 156 <table class="form-table"> 79 <tr valign="top">157 <tr valign="top"> 80 158 <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> 82 160 </tr> 83 161 <tr valign="top"> 84 162 <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> 86 164 </tr> 87 165 <tr valign="top"> 88 166 <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> 91 185 </table> 92 186 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> 99 195 100 196 <table class="form-table"> 101 197 <tr valign="top"> 102 198 <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> 104 200 </tr> 105 201 <tr valign="top"> 106 202 <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> 108 204 </tr> 109 205 <tr valign="top"> 110 206 <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> 112 208 </tr> 113 209 <tr valign="top"> 114 210 <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> 116 212 </tr> 117 213 </table> 118 214 119 <?php echo "<h3>" . __("Question Image", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>120 121 <p> 122 <?php123 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 ?> 126 222 </p> 127 223 128 224 <p> 129 <?php130 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 ?> 133 229 </p> 134 230 … … 138 234 <script> 139 235 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) ?>"; 142 238 143 239 // 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(); ?>); 150 246 151 247 highlight_list("#iamhuman_grid_question", "colour_one", colour_one_string); … … 171 267 <tr valign="top"> 172 268 <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> 174 270 </tr> 175 271 <tr valign="top"> 176 272 <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> 178 274 </tr> 179 275 <tr valign="top"> 180 276 <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> 182 278 </tr> 183 279 <tr valign="top"> 184 280 <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> 186 282 </tr> 187 283 </table> 188 284 189 <?php echo "<h3>" . __("Answer Image", IamHumanConstants::$IAMHUMAN_TEXT_DOMAIN) . "</h3>"; ?>190 <p> 191 <?php192 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 ?> 194 290 </p> 195 291 196 292 <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); ?> 198 294 <input type="button" id="copy_to_answer" value="Copy"/> 199 295 </p> … … 226 322 jQuery(function($) { 227 323 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); ?>"; 232 328 233 329 highlight_list("#iamhuman_grid_answer", "colour_one", answer_colour_one_string); … … 248 344 </script> 249 345 250 <?php submit_button(); ?>346 <?php submit_button(); ?> 251 347 </form> 252 348 </div> … … 259 355 add_options_page( 260 356 __('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 */ 364 function 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 */ 373 function 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 402 add_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 */ 409 function 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 */ 419 function 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 */ 441 function 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 456 function 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 84 84 grid_element.append(new_row); 85 85 } 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 87 93 return grid_element; 88 94 } … … 112 118 } 113 119 120 /** 121 * Removes all styles from all cells. 122 * 123 * @param string grid_selector 124 * @returns 125 */ 114 126 function clear_grid(grid_selector) { 115 127 jQuery(grid_selector + " .grid_cell").each(function() { … … 118 130 jQuery(this).addClass("colour_bg"); 119 131 }); 132 } 133 134 function delete_grid(grid_selector) { 135 jQuery(grid_selector).empty(); 120 136 } 121 137
Note: See TracChangeset
for help on using the changeset viewer.