1/** 2 * Entry Method Registry - JS wrapper 3 * 4 * Reads from window.ENTRY_METHOD_REGISTRY (JSON embedded by PHP) and provides 5 * the same function signatures the codebase currently calls: 6 * - entry_method_fetch_values(entry_method, entry_type, ...) 7 * - switch_entry_method_int_to_text(id) 8 * - switch_entry_method_text_to_int(text) 9 * - switch_entry_method_int_to_provider(id) 10 * - plan_entry_methods_plan_levels (object) 11 */ 12 13(function () { 14 var _data = null; 15 var _intToText = {}; 16 var _textToInt = {}; 17 var _intToProvider = {}; 18 19 // Default values matching the original function's variable initializations 20 var _defaults = { 21 // Top-level 22 input_category: 0, 23 api_auth: 0, 24 api_auth_required: 0, 25 social_optional_engagement: 0, 26 plan_level: 99, 27 28 // Flags 29 entry_title: 0, 30 entry_link: 0, 31 entry_amount: 0, 32 entry_textarea: 0, 33 daily: 0, 34 timer: 0, 35 required: 0, 36 custom_icon: 0, 37 additional_instructions: 0, 38 email_integration: 0, 39 viral_share: 0, 40 upload_a_file: 0, 41 entry_attachment: 0, 42 entry_has_group: 0, 43 custom_radio_options: 0, 44 input_type: 0, 45 require_verification: 0, 46 require_verification_checked_by_default: 1, 47 force_require_verification: 0, 48 49 // Style 50 color: "#fff", 51 background_color: "", 52 font_awesome_icon: "", 53 entry_icon_path: "", 54 55 // Widget strings 56 input_header: "", 57 input_placeholder: "", 58 link_button_text: "", 59 verify_header: "", 60 verify_button_text: "", 61 62 // Link validation 63 link_prepend: "", 64 host_name: "", 65 66 // Builder strings 67 entry_method_handle: "", 68 entry_method_handle_hint: "", 69 entry_method_docs_link: "", 70 entry_title_header: "", 71 entry_title_placeholder: "", 72 entry_title_value: "", 73 entry_link_header: "", 74 entry_link_placeholder: "code-1, code-2, code-3, etc...", 75 entry_link_validation: "", 76 entry_link_validation_error: "", 77 entry_amount_header: "Worth # entries", 78 entry_amount_placeholder: "minimum 1 maximum 999", 79 entry_textarea_header: "", 80 entry_textarea_placeholder: "", 81 entry_textarea_value: "", 82 entry_textarea_max_length: "", 83 entry_textarea_note: "", 84 entry_link_text: "", 85 placeholder_replace: "", 86 main_instructions_header: "Main Directions", 87 main_instructions_placeholder: "", 88 main_instructions_max_length: 1000, 89 additional_instructions_header: "Additional Instructions", 90 additional_instructions_placeholder: "Optional", 91 additional_instructions_value: "", 92 additional_instructions_max_length: 1000, 93 additional_instructions_note: "", 94 entry_attachment_header: "Upload and attach", 95 entry_attachment_hint: 96 "Supported formats are: .jpg, .jpeg, .gif, .png and Recommended size is 1200 x 628", 97 entry_attachment_value: "Upload file", 98 entry_attachment_validation: "~^.*\\.(jpg|jpeg|gif|png)$~", 99 entry_attachment_validation_error: 100 "Unsupported file format, currently we only support following formats: .jpg, .jpeg, .gif, .png", 101 require_verification_header: "", 102 social_optional_engagement_header: "", 103 input_field_type: "", 104 105 // Errors 106 entry_title_error: "", 107 entry_match_error: "", 108 entry_substring_match_error: "", 109 entry_link_error: "", 110 entry_amount_error: "How many entries this is worth: Min 1 - Max 9999", 111 entry_textarea_error: "", 112 input_error_1: "", 113 input_error_2: "", 114 email_integration_error: "", 115 viral_share_error: "", 116 117 // Array defaults 118 viral_share_options: [], 119 upload_a_file_ext: [], 120 }; 121 122 // Section map - determines where each attribute lives in the JSON 123 var _sectionMap = { 124 // Top-level 125 input_category: "top", 126 api_auth: "top", 127 api_auth_required: "top", 128 social_optional_engagement: "top", 129 plan_level: "top", 130 131 // Flags 132 entry_title: "flags", 133 entry_link: "flags", 134 entry_amount: "flags", 135 entry_textarea: "flags", 136 daily: "flags", 137 timer: "flags", 138 required: "flags", 139 custom_icon: "flags", 140 additional_instructions: "flags", 141 email_integration: "flags", 142 viral_share: "flags", 143 upload_a_file: "flags", 144 entry_attachment: "flags", 145 entry_has_group: "flags", 146 custom_radio_options: "flags", 147 input_type: "flags", 148 require_verification: "flags", 149 require_verification_checked_by_default: "flags", 150 force_require_verification: "flags", 151 152 // Style 153 color: "style", 154 background_color: "style", 155 font_awesome_icon: "style", 156 entry_icon_path: "style", 157 158 // Widget strings (need [NAME] replacement) 159 input_header: "widget", 160 input_placeholder: "widget", 161 link_button_text: "widget", 162 verify_header: "widget", 163 verify_button_text: "widget", 164 165 // Link validation 166 link_prepend: "link_validation", 167 host_name: "link_validation", 168 }; 169 170 function _load() { 171 if (_data !== null) return; 172 _data = window.ENTRY_METHOD_REGISTRY; 173 if (!_data || !_data.methods) return; 174 175 for (var text in _data.methods) { 176 if (!_data.methods.hasOwnProperty(text)) continue; 177 var def = _data.methods[text]; 178 var id = def.id; 179 _intToText[id] = text; 180 _textToInt[text] = id; 181 _intToProvider[id] = def.provider || "None"; 182 } 183 184 // Aliases 185 _intToText[113] = "user_details"; 186 _intToText[114] = "user_details"; 187 } 188 189 /** 190 * Replace hostname in URI, matching original replace_hostname() behavior. 191 */ 192 function _replaceHostname(host_name, uri) { 193 try { 194 // For full URLs, extract the path 195 if (uri.indexOf("://") !== -1) { 196 var a = document.createElement("a"); 197 a.href = uri; 198 var path = a.pathname; 199 return path.replace(/^\//, "").trim(); 200 } 201 // For bare values (usernames), return as-is 202 return uri; 203 } catch (e) { 204 return uri; 205 } 206 } 207 208 /** 209 * Compute the [NAME] replacement value. 210 */ 211 function _computeName(def, entry_title_db, entry_link_db) { 212 if (entry_title_db && entry_title_db !== "") { 213 return entry_title_db; 214 } 215 216 // Strip www. (matches original behavior - only www. actually takes effect) 217 var end_uri = entry_link_db.replace(/www\./gi, ""); 218 219 // Apply host_name stripping if applicable 220 var host_name = 221 def.link_validation && def.link_validation.host_name 222 ? def.link_validation.host_name 223 : ""; 224 if (host_name !== "") { 225 end_uri = _replaceHostname(host_name, end_uri); 226 } 227 228 return end_uri; 229 } 230 231 /** 232 * Drop-in replacement for entry_method_fetch_values(). 233 * Same signature and return values as the original 5,200-line function. 234 */ 235 window.entry_method_fetch_values = function ( 236 entry_method, 237 entry_type, 238 entry_title_db, 239 entry_link_db, 240 entry_textarea_db, 241 language, 242 translate 243 ) { 244 _load(); 245 246 if (!language) language = "en"; 247 if (!entry_link_db || entry_link_db === "") entry_link_db = "[NAME]"; 248 249 var def = _data && _data.methods ? _data.methods[entry_method] : null; 250 if (!def) { 251 return _defaults.hasOwnProperty(entry_type) ? _defaults[entry_type] : ""; 252 } 253 254 // These attributes have no return case in the original function 255 if ( 256 entry_type === "main_instructions_header" || 257 entry_type === "main_instructions_placeholder" || 258 entry_type === "main_instructions_max_length" 259 ) { 260 return null; 261 } 262 263 var section = _sectionMap[entry_type] || "builder"; 264 265 // Translation override for widget strings 266 if (section === "widget" && language !== "en" && translate) { 267 var trans = def.translations || {}; 268 if (trans[entry_type] !== undefined) { 269 var val = trans[entry_type]; 270 // Replace {key} placeholders 271 val = val.replace(/\{(\w+)\}/g, function (match, key) { 272 return translate[key] !== undefined ? translate[key] : match; 273 }); 274 // Replace [NAME] 275 val = val.replace( 276 /\[NAME\]/g, 277 _computeName(def, entry_title_db, entry_link_db) 278 ); 279 return val; 280 } 281 } 282 283 // Resolve value based on section 284 switch (section) { 285 case "top": 286 return def[entry_type] !== undefined 287 ? def[entry_type] 288 : _defaults[entry_type] !== undefined 289 ? _defaults[entry_type] 290 : ""; 291 292 case "flags": 293 return def.flags && def.flags[entry_type] !== undefined 294 ? def.flags[entry_type] 295 : _defaults[entry_type] !== undefined 296 ? _defaults[entry_type] 297 : 0; 298 299 case "style": 300 return def.style && def.style[entry_type] !== undefined 301 ? def.style[entry_type] 302 : _defaults[entry_type] !== undefined 303 ? _defaults[entry_type] 304 : ""; 305 306 case "link_validation": 307 return def.link_validation && 308 def.link_validation[entry_type] !== undefined 309 ? def.link_validation[entry_type] 310 : _defaults[entry_type] !== undefined 311 ? _defaults[entry_type] 312 : ""; 313 314 case "widget": 315 var wval = 316 def.widget && def.widget[entry_type] !== undefined 317 ? def.widget[entry_type] 318 : _defaults[entry_type] !== undefined 319 ? _defaults[entry_type] 320 : ""; 321 if (typeof wval === "string" && wval.indexOf("[NAME]") !== -1) { 322 wval = wval.replace( 323 /\[NAME\]/g, 324 _computeName(def, entry_title_db, entry_link_db) 325 ); 326 } 327 return wval; 328 329 case "builder": 330 default: 331 return def.builder && def.builder[entry_type] !== undefined 332 ? def.builder[entry_type] 333 : _defaults[entry_type] !== undefined 334 ? _defaults[entry_type] 335 : ""; 336 } 337 }; 338 339 /** 340 * Drop-in replacement for switch_entry_method_int_to_text(). 341 */ 342 window.switch_entry_method_int_to_text = function (entry_method) { 343 _load(); 344 entry_method = parseInt(entry_method); 345 return _intToText[entry_method] || "user_details"; 346 }; 347 348 /** 349 * Drop-in replacement for switch_entry_method_text_to_int(). 350 */ 351 window.switch_entry_method_text_to_int = function (entry_method) { 352 _load(); 353 return _textToInt[entry_method] || 1; 354 }; 355 356 /** 357 * Drop-in replacement for switch_entry_method_int_to_provider(). 358 * Returns the OAuth provider name for a given entry method ID. 359 */ 360 window.switch_entry_method_int_to_provider = function (entry_method) { 361 _load(); 362 entry_method = parseInt(entry_method); 363 return _intToProvider[entry_method] || "None"; 364 }; 365 366 /** 367 * Auto-generate plan_entry_methods_plan_levels from registry data. 368 */ 369 function _buildPlanLevels() { 370 _load(); 371 var levels = {}; 372 if (_data && _data.methods) { 373 for (var text in _data.methods) { 374 if (!_data.methods.hasOwnProperty(text)) continue; 375 var pl = _data.methods[text].plan_level; 376 if (pl !== undefined && pl !== 99) { 377 levels[text] = pl; 378 } 379 } 380 } 381 // Include template plan levels that aren't entry methods 382 levels["leaderboard_template"] = 5; 383 levels["instant_coupons_template"] = 5; 384 levels["instant_prizes_template"] = 5; 385 levels["milestones_template"] = 5; 386 return levels; 387 } 388 389 // Build plan levels on first load 390 window.plan_entry_methods_plan_levels = _buildPlanLevels(); 391 392 /** 393 * Batch-fetch all entry method field values in a single call. 394 * Returns an object keyed by field name (or field_name + "_val" / "_value"). 395 * 396 * Replaces 50+ sequential entry_method_fetch_values() calls with one call. 397 * 398 * @param {string} entry_method_class - The entry method text key (e.g. "twitter_follow") 399 * @param {string} language - Language code (e.g. "en") 400 * @param {*} translate - Translation object or falsy 401 * @returns {Object} Map of field names to their resolved values 402 */ 403 window.entry_method_fetch_all = function ( 404 entry_method_class, 405 language, 406 translate 407 ) { 408 var result = {}; 409 var i, field; 410 411 // Static fields - no DB params, no language/translate needed 412 var staticFields = [ 413 "entry_method_handle", 414 "entry_method_docs_link", 415 "entry_method_handle_hint", 416 "entry_title", 417 "entry_title_header", 418 "entry_title_placeholder", 419 "entry_title_value", 420 "entry_link", 421 "entry_link_header", 422 "entry_link_placeholder", 423 "entry_link_validation", 424 "entry_link_validation_error", 425 "entry_amount", 426 "entry_amount_header", 427 "entry_amount_placeholder", 428 "entry_textarea", 429 "entry_textarea_header", 430 "entry_textarea_placeholder", 431 "entry_textarea_value", 432 "entry_textarea_note", 433 "entry_textarea_max_length", 434 "daily", 435 "timer", 436 "social_optional_engagement", 437 "social_optional_engagement_header", 438 "require_verification", 439 "require_verification_header", 440 "require_verification_checked_by_default", 441 "force_require_verification", 442 "required", 443 "custom_icon", 444 "custom_radio_options", 445 "input_type", 446 "additional_instructions", 447 "additional_instructions_header", 448 "additional_instructions_placeholder", 449 "additional_instructions_value", 450 "additional_instructions_note", 451 "additional_instructions_max_length", 452 "entry_attachment", 453 "entry_attachment_header", 454 "entry_attachment_hint", 455 "entry_attachment_value", 456 "entry_attachment_validation", 457 "entry_attachment_validation_error", 458 "email_integration", 459 "upload_a_file", 460 "upload_a_file_ext", 461 "viral_share", 462 "make_a_purchase", 463 "viral_share_options", 464 "color", 465 "background_color", 466 "font_awesome_icon", 467 "api_auth", 468 "api_auth_required", 469 "input_header_placeholder", 470 ]; 471 472 for (i = 0; i < staticFields.length; i++) { 473 field = staticFields[i]; 474 result[field] = entry_method_fetch_values( 475 entry_method_class, 476 field, 477 "", 478 "", 479 "", 480 "", 481 "" 482 ); 483 } 484 485 // Error fields - stored as field_name + "_val" 486 var errorFields = [ 487 "entry_title_error", 488 "entry_link_error", 489 "entry_amount_error", 490 "entry_textarea_error", 491 "entry_match_error", 492 "input_error_1", 493 "input_error_2", 494 "email_integration_error", 495 ]; 496 497 for (i = 0; i < errorFields.length; i++) { 498 field = errorFields[i]; 499 result[field + "_val"] = entry_method_fetch_values( 500 entry_method_class, 501 field, 502 "", 503 "", 504 "", 505 "", 506 "" 507 ); 508 } 509 510 // Translated fields - use language/translate params, stored as field_name + "_value" 511 var translatedFields = [ 512 "input_header", 513 "link_button_text", 514 "verify_header", 515 "verify_button_text", 516 ]; 517 518 for (i = 0; i < translatedFields.length; i++) { 519 field = translatedFields[i]; 520 result[field + "_value"] = entry_method_fetch_values( 521 entry_method_class, 522 field, 523 "", 524 "", 525 "", 526 language, 527 translate 528 ); 529 } 530 531 return result; 532 }; 533})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.