Plugin Directory

Changeset 3149634


Ignore:
Timestamp:
09/10/2024 09:01:10 PM (19 months ago)
Author:
falcon13
Message:

Updated validation and filter helper functions, including splitting validation and filter functions into separate helper files.

Location:
kofc-state/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • kofc-state/trunk/admin.php

    r2831418 r3149634  
    55 * @Author          Chris Hood (http://chrishood.me)
    66 * @Link                http://onthegridwebdesign.com
    7  * @copyright       (c) 2016-2022, On the Grid Web Design LLC
     7 * @copyright       (c) 2016-2024, On the Grid Web Design LLC
    88 * @created         7/21/2016
    99 */
     
    2222    $otgkofcs_Scores_Model = new otgkofcs_Scores_Model();
    2323    require_once(OTGKOFCS_ROOT_PATH . 'helpers/view_helper.php');
    24     require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     24    require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    2525
    2626    $message_list = array();
     
    8282    $Score_Model = new otgkofcs_Scores_Model();
    8383    require_once(OTGKOFCS_ROOT_PATH . 'helpers/view_helper.php');
    84     require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     84    require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    8585
    8686    $message_list = array();
     
    168168    $Recruiting_Model = new otgkofcs_Recruiting_Model();
    169169    require_once(OTGKOFCS_ROOT_PATH . 'helpers/view_helper.php');
    170     require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     170    require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    171171   
    172172    $message_list = array();
     
    223223    // ***** Load Models, Helpers and Libraries *****
    224224    require_once(OTGKOFCS_ROOT_PATH . 'helpers/view_helper.php');
    225     require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     225    require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    226226   
    227227    $message_list = array();
     
    266266    $otgkofcs_Star_Model = new otgkofcs_Star_Model();
    267267    require_once(OTGKOFCS_ROOT_PATH . 'helpers/view_helper.php');
    268     require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     268    require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    269269
    270270    $message_list = array();
     
    325325    $Messages_Model = new otgkofcs_Messages_Model();
    326326    require_once(OTGKOFCS_ROOT_PATH . 'helpers/view_helper.php');
    327     require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     327    require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    328328
    329329    $message_list = array();
     
    367367    require_once(OTGKOFCS_ROOT_PATH . 'models/messages_model.php');
    368368    $otgkofcs_Messages_Model = new otgkofcs_Messages_Model();
    369     require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     369    require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    370370
    371371    // ***** Check for Get Variables *****
     
    393393    $otgkofcs_Star_Model = new otgkofcs_Star_Model();
    394394    require_once(OTGKOFCS_ROOT_PATH . 'helpers/view_helper.php');
    395     require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     395    require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    396396
    397397    $message_list = array();
  • kofc-state/trunk/helpers/validation_helper.php

    r3096237 r3149634  
    11<?php
    2 /** Validation and Filters Helper
    3  * @Package         Knights of Columbus State WP Plugin
     2/** Submitted Data Validation Helper, OTG WP Plugins Common File
     3 * @Package         com.onthegridwebdesign.wpp-kofc-state
    44 * @File                helpers/validation_helper.php
    55 * @Author          Chris Hood (https://onthegridwebdesign.com)
    6  * @Link                http://onthegridwebdesign.com
    7  * @copyright       (c) 2018-2022, On the Grid Web Design LLC
    8  * @created         2/24/2018
     6 * @Link                https://onthegridwebdesign.com/software
     7 * @copyright       (c) 2018-2024, On the Grid Web Design LLC
     8 * @created         9/10/2024
    99*/
    1010
    11 /** Gets and Cleans a Post Value
    12  * @param string $field
    13  * @param string $default
    14  * @param boolean $allow_html
    15  * @return string|null
    16  */
    17 function otgkofcs_get_request_string ($field, $default=null, $allow_html=false) {
    18     if (empty($_REQUEST[$field])) {
    19         return $default;
    20     } else {
    21         if ($allow_html)
    22             return trim(filter_var(stripslashes_deep($_REQUEST[$field]), FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW));
    23         else
    24             return trim(filter_var(stripslashes_deep($_REQUEST[$field]), FILTER_SANITIZE_SPECIAL_CHARS));
    25     }
    26 }
    27 
    28 /** Checks the Variable and Returns It as an Integer or Null
    29  * @param string $field
    30  * @param int $default
    31  * @return int|null
    32  */
    33 function otgkofcs_get_request_int ($field, $default=null) {
    34     if (empty($_REQUEST[$field]) || (!ctype_digit(trim($_REQUEST[$field])) && !is_int(trim($_REQUEST[$field])))) {
    35         if (is_int($default) || ctype_digit($default))
    36             $out = $default;
    37         else
    38             $out = null;
    39     } else {
    40         $out = (int)trim($_REQUEST[$field]);
    41     }
    42     return $out;
    43 }
    44 
    45 /** Gets and Cleans a Email Post Value
    46  * @param string $field
    47  * @param string $default
    48  * @return string|null
    49  */
    50 function otgkofcs_get_request_email ($field, $default=null) {
    51     if (empty($_REQUEST[$field])) {
    52         return $default;
    53     } else {
    54         return filter_var(trim($_REQUEST[$field]), FILTER_SANITIZE_EMAIL);
    55     }
    56 }
    57 
    58 /** Gets and Cleans a URL Value
    59  * @param string $field
    60  * @param string $default
    61  * @return string|null
    62  */
    63 function otgkofcs_get_request_link ($field, $default = null) {
    64     if (empty($_REQUEST[$field])) {
    65         return $default;
    66     } else {
    67         $link = trim(stripslashes_deep($_REQUEST[$field]));
    68         if (0 != strncasecmp($link, 'http://', 7) && 0 != strncasecmp($link, 'https://', 8))
    69             $link = 'http://' . $link;
    70         return filter_var($link, FILTER_SANITIZE_URL);
    71     }
    72 }
    73 
    74 /** Gets and Cleans a Textarea Post
    75  * @param string $field
    76  * @param string $default
    77  * @return string|null
    78  */
    79 function otgkofcs_get_request_texarea ($field, $default = null) {
    80     if (empty($_REQUEST[$field])) {
    81         return $default;
    82     } else {
    83         return trim(filter_var(stripslashes_deep($_REQUEST[$field]), FILTER_SANITIZE_SPECIAL_CHARS));
    84     }
    85 }
    86 
    87 /** Get the Bulk Action List and Only Allows Integers in the List
     11/** Cleans and Checks an Email Address
     12 * @param string $in
    8813 * @return array
    8914 */
    90 function otgkofcs_get_bulk_action_list () {
    91     $bulk_action_list = array();
    92     if (!empty($_POST['bulk_action_list'])) foreach ($_POST['bulk_action_list'] as $id) {
    93         if (is_int($id) || ctype_digit($id)) {
    94             $bulk_action_list[] = (int)$id;
    95         }
     15function otgkofcs_validate_email ($in) {
     16    if (empty($in))
     17        return ['email' => '', 'valid' => false, 'message' => 'Email address needs to be submitted.'];
     18
     19    $valid = true;
     20    $message = '';
     21
     22    if (!$email_domain = stristr($in, '@')) {
     23        $message = 'Email address needs a "@"!';
     24        $valid = false;
     25    } elseif (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-]).*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $in)) {
     26        $message = 'Email address is missing something!';
     27        $valid = false;
     28    } elseif (!stristr($email_domain, '.')) {
     29        $message = 'Email address domain needs to be valid!';
     30        $valid = false;
     31    } elseif (!filter_var($in, FILTER_VALIDATE_EMAIL)) {
     32        $message = 'Email address needs to be valid!';
     33        $valid = false;
    9634    }
    97     return $bulk_action_list;
    98 }
    9935
    100 /** Get the Bulk Action List and Only Allows Integers in the List
    101  * @return array
    102  */
    103 function otgkofcs_get_request_int_array ($field = 'bulk_action_list') {
    104     $bulk_action_list = array();
    105     if (!empty($_POST[$field])) foreach ($_POST[$field] as $key => $value) {
    106         if (is_int($value) || ctype_digit($value)) {
    107             $bulk_action_list[$key] = (int)$value;
    108         }
    109     }
    110     return $bulk_action_list;
    111 }
    112 
    113 /** Get the Bulk Action List and Only Allows Integers in the List
    114  * @param string $field
    115  * @return array
    116  */
    117 function otgkofcs_get_request_str_array ($field) {
    118     $field_array = array();
    119     if (!empty($_POST[$field])) foreach ($_POST[$field] as $key => $value) {
    120         $field_array[trim(filter_var(stripslashes_deep($key), FILTER_SANITIZE_SPECIAL_CHARS))] = trim(filter_var(stripslashes_deep($value), FILTER_SANITIZE_SPECIAL_CHARS));
    121     }
    122     return $field_array;
    123 }
    124 
    125 /** Replace Quotes with HTML Entity Names
    126  * @param string $in
    127  * @return string
    128  */
    129 function otgkofcs_filter_quotes ($in) {
    130     return trim(str_replace(['"', "'"], ['&quot;', '&apos;'], $in));
     36    return ['valid' => $valid, 'message' => $message];
    13137}
    13238
     
    13440 * @return boolean
    13541 */
    136 function otgkofcs_verify_hcaptcha () { 
     42function otgkofcs_verify_hcaptcha () {
    13743    $post_data['secret'] = get_option('otgkofcs_hcaptcha_secret_key');
    13844    if (empty($post_data['secret'])) return true; // hcaptcha is disabled
     
    14551    $response = curl_exec($curl);
    14652    $response_data = json_decode($response, true);
    147     //$response = wp_remote_post('https://hcaptcha.com/siteverify', ['body' => $post_data]);
    148     //$response_data = json_decode($response['body'], true);
    149    
     53
    15054    /* ***** For Debugging *****
    15155    $curl_error = curl_error($curl);
     
    15963    /**/
    16064
    161     if ($response_data['success'])
     65    if ('true' == $response_data['success']) {
    16266        return true;
    163        
    164     return false;
     67    } else {
     68        return false;
     69    }
    16570}
  • kofc-state/trunk/kofc-state.php

    r2908729 r3149634  
    55  Description: Functionality for State Councils Including Recruiting Scoreboards
    66  Author: Chris Hood, On The Grid Web Design LLC
    7   Version: 2.4.3
     7  Version: 2.5.0
    88  Author URI: https://onthegridwebdesign.com
    9   Updated: 12/8/2022 Created: 7/21/2016
     9  Updated: 9/10/2024 Created: 7/21/2016
    1010 */
    1111
     
    5555
    5656/** Load CSS and JS Files
    57  */
     57 */ 
    5858function otgkofcs_scripts () {
    5959    wp_register_style('otgkofcs_css', plugins_url('kofc-state.min.css', __FILE__));
     
    9797    $table_messages = $wpdb->prefix . 'otgkofcs_messages';
    9898    $charset_collate = $wpdb->get_charset_collate();
    99 
     99           
    100100    // *** Knights Table ***
    101101    $sql_knights = "CREATE TABLE $table_knights (
     
    127127    dbDelta($sql_district_scores);
    128128    if (!get_option('otgkofcs_number_of_districts')) update_option('otgkofcs_number_of_districts', 12);
    129 
     129   
    130130    // *** Star Council Requiments Table ***
    131131    $sql_star_requirements = "CREATE TABLE $table_star_requirements (
     
    136136        ) $charset_collate;";
    137137    dbDelta($sql_star_requirements);
    138 
     138   
    139139    // *** Star Council Requiments Met Table ***
    140140    $sql_star_reqs_met = "CREATE TABLE $table_star_reqs_met (
     
    144144        ) $charset_collate;";
    145145    dbDelta($sql_star_reqs_met);
    146 
     146   
    147147    // *** Messages Table ***
    148148    $sql_messages = "CREATE TABLE $table_messages (
     
    157157        PRIMARY KEY (`message_id`)
    158158        ) $charset_collate;";
    159     dbDelta($sql_messages);
     159    dbDelta($sql_messages); 
    160160}
    161161
  • kofc-state/trunk/readme.txt

    r3096237 r3149634  
    44Tags: knights of columbus, widget, shortcode, kofc
    55Requires at least: 4.0
    6 Tested up to: 6.5
     6Tested up to: 6.6
    77Requires PHP: 5.6
    8 Stable tag: 2.4.4
     8Stable tag: 2.5.0
    99License: GPLv3
    1010
     
    2626
    2727== Installation ==
    28 After activating go to the settings page. Here you can set the number of districts you have. To enable spam reduction on the email forms, Google reCaptcha keys are required. Links to the settings page are under Settings in the admin and on the plugins page. 
     28After activating go to the settings page. Here you can set the number of districts you have. To enable spam reduction on the email forms, Google reCaptcha keys are required. Links to the settings page are under Settings in the admin and on the plugins page.
    2929The admin menu will have the two new post types in the main admin menu along with the Scoreboard and Inbound Messages menu items.
    3030
     
    7474
    7575== Changelog ==
     762.5.0 (9/10/2024)
     77- Updated validation and filter helper functions, including splitting validation and filter functions into separate helper files.
     78
    76792.4.4 (6/1/2024)
    7780- Small tweaks
  • kofc-state/trunk/type-assembly.php

    r2831418 r3149634  
    174174        }
    175175
    176         require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     176        require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    177177
    178178        $text_field_list = ['name', 'location', 'charter_date', 'faithful_navigator', 'faithful_comptroller', 'color_corps_commander', 'twitter', 'instagram'];
     
    319319     */
    320320    function email_assembly_form () {
    321         require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
    322321        require_once('models/messages_model.php');
    323322        $otgkofcs_Messages_Model = new otgkofcs_Messages_Model();
     323        require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
     324        require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
    324325       
    325326        // ***** Form Valdiation *****
  • kofc-state/trunk/type-council.php

    r2831418 r3149634  
    189189        }
    190190
    191         require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     191        require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    192192
    193193        $text_field_list = ['name', 'location', 'contact_email', 'grand_knight', 'district', 'assembly', 'charter_date', 'twitter', 'instagram'];
     
    322322     */
    323323    function email_council_form () {
    324         require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
    325324        require_once('models/messages_model.php');
    326325        $otgkofcs_Messages_Model = new otgkofcs_Messages_Model();
     326        require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
     327        require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
    327328       
    328329        // ***** Form Valdiation *****
  • kofc-state/trunk/type-knight.php

    r2831418 r3149634  
    5050            'description' => '',
    5151            'labels' => $labels,
    52             'supports' => array('title', 'editor', 'thumbnail'),
     52            'supports' => ['title', 'editor', 'thumbnail'],
    5353            'hierarchical' => false,
    5454            'public' => true,
     
    155155        }
    156156       
    157         require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
     157        require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
    158158
    159159        $text_field_list = ['name_first', 'name_last',  'council', 'twitter', 'instagram'];
     
    281281     */
    282282    function email_knight_form () {
    283         require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
    284283        require_once('models/messages_model.php');
    285284        $otgkofcs_Messages_Model = new otgkofcs_Messages_Model();
     285        require_once(OTGKOFCS_ROOT_PATH . 'helpers/filter_helper.php');
     286        require_once(OTGKOFCS_ROOT_PATH . 'helpers/validation_helper.php');
    286287       
    287288        // ***** Form Valdiation *****
  • kofc-state/trunk/views/admin/star_reqs.php

    r2831418 r3149634  
    2828        </ul>
    2929
    30         <input type="submit">
     30        <input type="submit" value="Save Changes">
    3131        <script>
    3232         jQuery(function($) {
     
    4343    <form id="otgkofcs_star_req_add_form" class="edit" method="post">
    4444        <?php wp_nonce_field('star_reqs_add'); ?>
    45         <h3>Add Requirement</h3>
     45        <h3>Add a Requirement</h3>
    4646        <input type="text" id="otgkofcs_title" name="new_name" placeholder="Requirement Name" required="required" maxlength="250" style="width: 400px;">
    47         <input type="submit">
     47        <input type="submit" value="Add">
    4848    </form>
    4949</div>
Note: See TracChangeset for help on using the changeset viewer.