Plugin Directory

Changeset 3149586


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

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

Location:
business-listing/trunk
Files:
1 added
5 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • business-listing/trunk/admin.php

    r2831458 r3149586  
    55 * @Author          Chris Hood (http://chrishood.me)
    66 * @Link                https://onthegridwebdesign.com
    7  * @copyright       (c) 2015-2022, On the Grid Web Design LLC
     7 * @copyright       (c) 2015-2024, On the Grid Web Design LLC
    88 * @created         4/23/15
    99*/
     
    2121    $otgblist_Listings_Model = new otgblist_Listings_Model();
    2222    include_once(OTGBLIST_ROOT_PATH . 'helpers/view_helper.php');
    23     include_once(OTGBLIST_ROOT_PATH . 'helpers/validation_helper.php');
     23    include_once(OTGBLIST_ROOT_PATH . 'helpers/filter_helper.php');
    2424   
    2525    $message_list = array();
     
    2929        check_admin_referer('list');
    3030        $action = otgblist_get_request_string('action');
    31         $bulk_action_list = otgblist_get_bulk_action_list();
     31        $bulk_action_list = otgblist_get_request_int_array();
    3232
    3333        if (empty($bulk_action_list)) {
     
    9393    $otgblist_Cats_Model = new otgblist_Cats_Model();
    9494    include_once(OTGBLIST_ROOT_PATH . 'helpers/view_helper.php');
    95     include_once(OTGBLIST_ROOT_PATH . 'helpers/validation_helper.php');
     95    include_once(OTGBLIST_ROOT_PATH . 'helpers/filter_helper.php');
    9696   
    9797    $message_list = array();
     
    154154    $otgblist_Cats_Model = new otgblist_Cats_Model();
    155155    include_once(OTGBLIST_ROOT_PATH . 'helpers/view_helper.php');
    156     include_once(OTGBLIST_ROOT_PATH . 'helpers/validation_helper.php');
     156    include_once(OTGBLIST_ROOT_PATH . 'helpers/filter_helper.php');
    157157   
    158158    $message_list = array();
     
    162162        check_admin_referer('regions');
    163163        $action = otgblist_get_request_string('action');
    164         $bulk_action_list = otgblist_get_bulk_action_list();
     164        $bulk_action_list = otgblist_get_request_int_array();
    165165        if (empty($bulk_action_list)) {
    166166            $message_list[] = ['Nothing to do that to.', 3, 2];
     
    233233    $otgblist_Cats_Model = new otgblist_Cats_Model();
    234234    include_once(OTGBLIST_ROOT_PATH . 'helpers/view_helper.php');
    235     include_once(OTGBLIST_ROOT_PATH . 'helpers/validation_helper.php');
     235    include_once(OTGBLIST_ROOT_PATH . 'helpers/filter_helper.php');
    236236   
    237237    $message_list = array();
     
    266266    $otgblist_Cats_Model = new otgblist_Cats_Model();
    267267    include_once(OTGBLIST_ROOT_PATH . 'helpers/view_helper.php');
    268     include_once(OTGBLIST_ROOT_PATH . 'helpers/validation_helper.php');
     268    include_once(OTGBLIST_ROOT_PATH . 'helpers/filter_helper.php');
    269269   
    270270    $message_list = array();
     
    274274        check_admin_referer('categories');
    275275        $action = otgblist_get_request_string('action');
    276         $bulk_action_list = otgblist_get_bulk_action_list();
     276        $bulk_action_list = otgblist_get_request_int_array();
    277277
    278278        if (empty($bulk_action_list)) {
     
    346346    $otgblist_Cats_Model = new otgblist_Cats_Model();
    347347    include_once(OTGBLIST_ROOT_PATH . 'helpers/view_helper.php');
    348     include_once(OTGBLIST_ROOT_PATH . 'helpers/validation_helper.php');
     348    include_once(OTGBLIST_ROOT_PATH . 'helpers/filter_helper.php');
    349349   
    350350    $message_list = array();
     
    377377    // ***** Load Models, Helpers and Libraries *****
    378378    include_once(OTGBLIST_ROOT_PATH . 'helpers/view_helper.php');
    379     include_once(OTGBLIST_ROOT_PATH . 'helpers/validation_helper.php');
     379    include_once(OTGBLIST_ROOT_PATH . 'helpers/filter_helper.php');
    380380   
    381381    $message_list = array();   
     
    417417    wp_enqueue_style('otgcalgs_datatables_css');
    418418    wp_enqueue_script('otgcalgs_datatables', plugins_url('datatables.min.js', __FILE__));
    419     include_once(OTGBLIST_ROOT_PATH . 'helpers/validation_helper.php');
     419    include_once(OTGBLIST_ROOT_PATH . 'helpers/filter_helper.php');
    420420   
    421421    // ***** wp_enqueue_media Long Form to Go Around Bugs *****
  • business-listing/trunk/business-listing.css

    r2674650 r3149586  
    44 * @Author          Chris Hood (http://chrishood.me)
    55 * @Link                https://onthegridwebdesign.com
    6  * @copyright       (c) 2015-2022, On the Grid Web Design LLC
     6 * @copyright       (c) 2015-2024, On the Grid Web Design LLC
    77 * @created         4/23/15
    88*/
     
    170170.otgblist_table1 th {
    171171    padding: 6px 12px;
     172    text-align: center !important;
    172173}
    173174.otgblist_table1 th a {
  • business-listing/trunk/business-listing.php

    r2831421 r3149586  
    55  Description: List businesses in tiles with a photo and link in a random order
    66  Author: Chris Hood, On The Grid Web Design LLC
    7   Version: 2.1.2
     7  Copyright: (c) 2015-2024, On the Grid Web Design LLC
     8  Version: 2.2
    89  Author URI: https://chrishood.me
    9   Updated: 12/9/2022; Created: 4/23/2015
     10  Updated: 9/10/2024; Created: 4/23/2015
    1011 */
    1112
  • business-listing/trunk/helpers/validation_helper.php

    r2831458 r3149586  
    11<?php
    2 /** Form Validation Helper, OTG WP Plugins Common File
     2/** Submitted Data Validation Helper, OTG WP Plugins Common File
    33 * @Package         com.onthegridwebdesign.wpp-business-listings
    44 * @File                helpers/validation_helper.php
    55 * @Author          Chris Hood (https://onthegridwebdesign.com)
    66 * @Link                https://onthegridwebdesign.com/software
    7  * @copyright       (c) 2018-2022, On the Grid Web Design LLC
    8  * @created         2/24/2018
     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
     11/** Cleans and Checks an Email Address
     12 * @param string $in
     13 * @return array
    1614 */
    17 function otgblist_get_request_string ($field, $default=null, $allow_html=false) {
    18     if (empty($_REQUEST[$field])) {
    19         return $default;
     15function otgblist_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;
     34    }
     35
     36    return ['valid' => $valid, 'message' => $message];
     37}
     38
     39
     40/** Verifies a hCaptcha
     41 * @return boolean
     42 */
     43function otgblist_verify_hcaptcha () {
     44    $post_data['secret'] = get_option('otgblist_hcaptcha_secret_key');
     45    if (empty($post_data['secret'])) return true; // hcaptcha is disabled
     46    $post_data['response'] = otgblist_get_request_string('h-captcha-response');
     47
     48    $curl = curl_init('https://hcaptcha.com/siteverify');
     49    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     50    curl_setopt($curl, CURLOPT_POST, 1);
     51    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
     52    $response = curl_exec($curl);
     53    $response_data = json_decode($response, true);
     54
     55    /* ***** For Debugging *****
     56    $curl_error = curl_error($curl);
     57    if (!empty($curl_error)) {
     58        error_log('otgblist_verify_hcaptcha Curl Error: ' . print_r($curl_error, true));
     59    }
     60    $curl_info = curl_getinfo($curl);
     61    error_log('otgblist_verify_hcaptcha Curl Info: ' . print_r($curl_info, true));
     62    error_log('otgblist_verify_hcaptcha Response: ' . $response);
     63    error_log('otgblist_verify_hcaptcha Response Array: ' . print_r($response_data, true));
     64    /**/
     65
     66    if ('true' == $response_data['success']) {
     67        return true;
    2068    } 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));
     69        return false;
    2570    }
    2671}
    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 otgblist_get_request_int ($field, $default=null) {
    34     $value = trim($_REQUEST[$field]);
    35     if (!is_numeric($value) && !is_int($value)) {
    36         if (is_int($default) || is_numeric($default))
    37             $out = $default;
    38         else
    39             $out = null;
    40     } else {
    41         $out = (int)$value;
    42     }
    43     return $out;
    44 }
    45 
    46 /** Gets and Cleans a Email Post Value
    47  * @param string $field
    48  * @param string $default
    49  * @return string|null
    50  */
    51 function otgblist_get_request_email ($field, $default=null) {
    52     if (empty($_REQUEST[$field])) {
    53         return $default;
    54     } else {
    55         return filter_var(trim($_REQUEST[$field]), FILTER_SANITIZE_EMAIL);
    56     }
    57 }
    58 
    59 /** Gets and Cleans a URL Value
    60  * @param string $field
    61  * @param string $default
    62  * @return string|null
    63  */
    64 function otgblist_get_request_link ($field, $default = null) {
    65     if (empty($_REQUEST[$field])) {
    66         return $default;
    67     } else {
    68         $link = trim(stripslashes_deep($_REQUEST[$field]));
    69         if (0 != strncasecmp($link, 'http://', 7) && 0 != strncasecmp($link, 'https://', 8))
    70             $link = 'http://' . $link;
    71         return filter_var($link, FILTER_SANITIZE_URL);
    72     }
    73 }
    74 
    75 /** Gets and Cleans a Textarea Post
    76  * @param string $field
    77  * @param string $default
    78  * @return string|null
    79  */
    80 function otgblist_get_request_texarea ($field, $default = null) {
    81     if (empty($_REQUEST[$field])) {
    82         return $default;
    83     } else {
    84         return trim(filter_var(stripslashes_deep($_REQUEST[$field]), FILTER_SANITIZE_SPECIAL_CHARS));
    85     }
    86 }
    87 
    88 /** Get the Bulk Action List and Only Allows Integers in the List
    89  * @return array
    90  */
    91 function otgblist_get_bulk_action_list () {
    92     $bulk_action_list = array();
    93     if (!empty($_POST['bulk_action_list'])) foreach ($_POST['bulk_action_list'] as $id) {
    94         if (is_int($id) || ctype_digit($id)) {
    95             $bulk_action_list[] = (int)$id;
    96         }
    97     }
    98     return $bulk_action_list;
    99 }
    100 
    101 /** Get the Bulk Action List and Only Allows Integers in the List
    102  * @return array
    103  */
    104 function otgblist_get_request_int_array ($field = 'bulk_action_list') {
    105     $bulk_action_list = array();
    106     if (!empty($_POST[$field])) foreach ($_POST[$field] as $key => $value) {
    107         if (is_int($value) || ctype_digit($value)) {
    108             $bulk_action_list[$key] = (int)$value;
    109         }
    110     }
    111     return $bulk_action_list;
    112 }
    113 
    114 /** Get the Bulk Action List and Only Allows Integers in the List
    115  * @param string $field
    116  * @return array
    117  */
    118 function otgblist_get_request_str_array ($field) {
    119     $field_array = array();
    120     if (!empty($_POST[$field])) foreach ($_POST[$field] as $key => $value) {
    121         $field_array[trim(filter_var(stripslashes_deep($key), FILTER_SANITIZE_SPECIAL_CHARS))] = trim(filter_var(stripslashes_deep($value), FILTER_SANITIZE_SPECIAL_CHARS));
    122     }
    123     return $field_array;
    124 }
    125 
    126 /** Replace Quotes with HTML Entity Names
    127  * @param string $in
    128  * @return string
    129  */
    130 function otgblist_filter_quotes ($in) {
    131     return trim(str_replace(['"', "'"], ['&quot;', '&apos;'], $in));
    132 }
  • business-listing/trunk/readme.txt

    r2831422 r3149586  
    44Tags: business, listings, shortcode, thumbnail, business directory
    55Requires at least: 4.0
    6 Tested up to: 6.1
     6Tested up to: 6.6
    77Requires PHP: 5.6
    8 Stable tag: 2.1.2
     8Stable tag: 2.2.0
    99License: GPLv3
    1010
     
    4646
    4747== Changelog ==
     482.2.0 (9/10/2024)
     49- Updated validation and filter helper functions, including splitting validation and filter functions into separate helper files.
     50
    48512.1.2 (12/9/2022)
    4952- Validation, Filter and View helpers improvements and updates for PHP 8.2.
     
    7376
    7477== Frequently Asked Questions ==
    75 
    7678= Can I change the button color? =
    7779* Right now you have to override the colors by CSS. In a future version it'll be in the options.
  • business-listing/trunk/shortcodes.php

    r2531520 r3149586  
    7676                if (empty($listing['link'])) $listing['link'] = '#';
    7777                $output .= '<a href="' . $listing['link'] . '" target="_blank" rel="noopener" class="otgblist_box_img_outer">';
    78                 $output .= '<img src="' . esc_url($image_url[0]). '" alt="' . esc_attr($image_alt) . '">';
     78                if (!empty($image_url[0])) $output .= '<img src="' . esc_url($image_url[0]). '" alt="' . esc_attr($image_alt) . '">';
    7979                $output .= '</a>';
    8080            }
Note: See TracChangeset for help on using the changeset viewer.