Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/blocksy-companion-pro   php

Repository URL to install this package:

Version: 1.8.76 

/ includes / fs-core-functions.php

<?php
    /**
     * @package     Freemius
     * @copyright   Copyright (c) 2015, Freemius, Inc.
     * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
     * @since       1.0.3
     */

    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }

    if ( ! function_exists( 'fs_dummy' ) ) {
        function fs_dummy() {
        }
    }

    /* Url.
    --------------------------------------------------------------------------------------------*/
    if ( ! function_exists( 'fs_get_url_daily_cache_killer' ) ) {
        function fs_get_url_daily_cache_killer() {
            return date( '\YY\Mm\Dd' );
        }
    }

    /* Templates / Views.
    --------------------------------------------------------------------------------------------*/
    if ( ! function_exists( 'fs_get_template_path' ) ) {
        function fs_get_template_path( $path ) {
            return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
        }

        function fs_include_template( $path, &$params = null ) {
            $VARS = &$params;
            include fs_get_template_path( $path );
        }

        function fs_include_once_template( $path, &$params = null ) {
            $VARS = &$params;
            include_once fs_get_template_path( $path );
        }

        function fs_require_template( $path, &$params = null ) {
            $VARS = &$params;
            require fs_get_template_path( $path );
        }

        function fs_require_once_template( $path, &$params = null ) {
            $VARS = &$params;
            require_once fs_get_template_path( $path );
        }

        function fs_get_template( $path, &$params = null ) {
            ob_start();

            $VARS = &$params;
            require fs_get_template_path( $path );

            return ob_get_clean();
        }
    }

    /* Scripts and styles including.
    --------------------------------------------------------------------------------------------*/

    if ( ! function_exists( 'fs_asset_url' ) ) {
        /**
         * Generates an absolute URL to the given path. This function ensures that the URL will be correct whether the asset
         * is inside a plugin's folder or a theme's folder.
         *
         * Examples:
         * 1. "themes" folder
         *    Path: C:/xampp/htdocs/fswp/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css
         *    URL: http://fswp:8080/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css
         *
         * 2. "plugins" folder
         *    Path: C:/xampp/htdocs/fswp/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css
         *    URL: http://fswp:8080/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css
         *
         * @author Leo Fajardo (@leorw)
         * @since  1.2.2
         *
         * @param  string $asset_abs_path Asset's absolute path.
         *
         * @return string Asset's URL.
         */
        function fs_asset_url( $asset_abs_path ) {
            $wp_content_dir = fs_normalize_path( WP_CONTENT_DIR );
            $asset_abs_path = fs_normalize_path( $asset_abs_path );

            if ( 0 === strpos( $asset_abs_path, $wp_content_dir ) ) {
                // Handle both theme and plugin assets located in the standard directories.
                $asset_rel_path = str_replace( $wp_content_dir, '', $asset_abs_path );
                $asset_url      = content_url( fs_normalize_path( $asset_rel_path ) );
            } else {
                $wp_plugins_dir = fs_normalize_path( WP_PLUGIN_DIR );
                if ( 0 === strpos( $asset_abs_path, $wp_plugins_dir ) ) {
                    // Try to handle plugin assets that may be located in a non-standard plugins directory.
                    $asset_rel_path = str_replace( $wp_plugins_dir, '', $asset_abs_path );
                    $asset_url      = plugins_url( fs_normalize_path( $asset_rel_path ) );
                } else {
                    // Try to handle theme assets that may be located in a non-standard themes directory.
                    $active_theme_stylesheet = get_stylesheet();
                    $wp_themes_dir           = fs_normalize_path( trailingslashit( get_theme_root( $active_theme_stylesheet ) ) );
                    $asset_rel_path          = str_replace( $wp_themes_dir, '', fs_normalize_path( $asset_abs_path ) );
                    $asset_url               = trailingslashit( get_theme_root_uri( $active_theme_stylesheet ) ) . fs_normalize_path( $asset_rel_path );
                }
            }

            return $asset_url;
        }
    }

    if ( ! function_exists( 'fs_enqueue_local_style' ) ) {
        function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
            wp_enqueue_style( $handle, fs_asset_url( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ), $deps, $ver, $media );
        }
    }

    if ( ! function_exists( 'fs_enqueue_local_script' ) ) {
        function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
            wp_enqueue_script( $handle, fs_asset_url( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ), $deps, $ver, $in_footer );
        }
    }

    if ( ! function_exists( 'fs_img_url' ) ) {
        function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
            return ( fs_asset_url( $img_dir . '/' . trim( $path, '/' ) ) );
        }
    }

    #--------------------------------------------------------------------------------
    #region Request handlers.
    #--------------------------------------------------------------------------------

    if ( ! function_exists( 'fs_request_get' ) ) {
        /**
         * A helper method to fetch GET/POST user input with an optional default value when the input is not set.
         * @author Vova Feldman (@svovaf)
         *
         * @param string      $key
         * @param mixed       $def
         * @param string|bool $type Since 1.2.1.7 - when set to 'get' will look for the value passed via querystring, when
         *                          set to 'post' will look for the value passed via the POST request's body, otherwise,
         *                          will check if the parameter was passed in any of the two.
         *
         * @return mixed
         */
        function fs_request_get( $key, $def = false, $type = false ) {
            if ( is_string( $type ) ) {
                $type = strtolower( $type );
            }

            /**
             * Note to WordPress.org Reviewers:
             *  This is a helper method to fetch GET/POST user input with an optional default value when the input is not set. The actual sanitization is done in the scope of the function's usage.
             */
            switch ( $type ) {
                case 'post':
                    $value = isset( $_POST[ $key ] ) ? $_POST[ $key ] : $def;
                    break;
                case 'get':
                    $value = isset( $_GET[ $key ] ) ? $_GET[ $key ] : $def;
                    break;
                default:
                    $value = isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
                    break;
            }

            return $value;
        }
    }

    if ( ! function_exists( 'fs_request_has' ) ) {
        function fs_request_has( $key ) {
            return isset( $_REQUEST[ $key ] );
        }
    }

    if ( ! function_exists( 'fs_request_get_bool' ) ) {
        /**
         * A helper method to fetch GET/POST user boolean input with an optional default value when the input is not set.
         *
         * @author Vova Feldman (@svovaf)
         *
         * @param string $key
         * @param bool $def
         *
         * @return bool|mixed
         */
        function fs_request_get_bool( $key, $def = false ) {
            $val = fs_request_get( $key, null );

            if ( is_null( $val ) ) {
                return $def;
            }

            if ( is_bool( $val ) ) {
                return $val;
            } else if ( is_numeric( $val ) ) {
                if ( 1 == $val ) {
                    return true;
                } else if ( 0 == $val ) {
                    return false;
                }
            } else if ( is_string( $val ) ) {
                $val = strtolower( $val );

                if ( 'true' === $val ) {
                    return true;
                } else if ( 'false' === $val ) {
                    return false;
                }
            }

            return $def;
        }
    }

    if ( ! function_exists( 'fs_request_is_post' ) ) {
        function fs_request_is_post() {
            return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
        }
    }

    if ( ! function_exists( 'fs_request_is_get' ) ) {
        function fs_request_is_get() {
            return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
        }
    }

    if ( ! function_exists( 'fs_get_action' ) ) {
        function fs_get_action( $action_key = 'action' ) {
            if ( ! empty( $_REQUEST[ $action_key ] ) && is_string( $_REQUEST[ $action_key ] ) ) {
                return strtolower( $_REQUEST[ $action_key ] );
            }

            if ( 'action' == $action_key ) {
                $action_key = 'fs_action';

                if ( ! empty( $_REQUEST[ $action_key ] ) && is_string( $_REQUEST[ $action_key ] ) ) {
                    return strtolower( $_REQUEST[ $action_key ] );
                }
            }

            return false;
        }
    }

    if ( ! function_exists( 'fs_request_is_action' ) ) {
        function fs_request_is_action( $action, $action_key = 'action' ) {
            return ( strtolower( $action ) === fs_get_action( $action_key ) );
        }
    }

    if ( ! function_exists( 'fs_request_is_action_secure' ) ) {
        /**
         * @author Vova Feldman (@svovaf)
         * @since  1.0.0
         *
         * @since  1.2.1.5 Allow nonce verification.
         *
         * @param string $action
         * @param string $action_key
         * @param string $nonce_key
         *
         * @return bool
         */
        function fs_request_is_action_secure(
            $action,
            $action_key = 'action',
            $nonce_key = 'nonce'
        ) {
            if ( strtolower( $action ) !== fs_get_action( $action_key ) ) {
                return false;
            }

            $nonce = ! empty( $_REQUEST[ $nonce_key ] ) ?
                $_REQUEST[ $nonce_key ] :
                '';

            if ( empty( $nonce ) ||
                 ( false === wp_verify_nonce( $nonce, $action ) )
            ) {
                return false;
            }

            return true;
        }
    }

    #endregion

    if ( ! function_exists( 'fs_is_plugin_page' ) ) {
        function fs_is_plugin_page( $page_slug ) {
            return ( is_admin() && $page_slug === fs_request_get( 'page' ) );
        }
    }

    if ( ! function_exists( 'fs_get_raw_referer' ) ) {
        /**
         * Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
         *
         * Do not use for redirects, use {@see wp_get_referer()} instead.
         *
         * @since 1.2.3
         *
         * @return string|false Referer URL on success, false on failure.
         */
        function fs_get_raw_referer() {
            if ( function_exists( 'wp_get_raw_referer' ) ) {
                return wp_get_raw_referer();
            }
            if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
                return wp_unslash( $_REQUEST['_wp_http_referer'] );
            } else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
                return wp_unslash( $_SERVER['HTTP_REFERER'] );
            }

            return false;
        }
    }

    /* Core UI.
    --------------------------------------------------------------------------------------------*/
    if ( ! function_exists( 'fs_ui_action_button' ) ) {
        /**
         * @param number      $module_id
         * @param string      $page
         * @param string      $action
         * @param string      $title
         * @param string      $button_class
         * @param array       $params
         * @param bool        $is_primary
         * @param bool        $is_small
         * @param string|bool $icon_class   Optional class for an icon (since 1.1.7).
         * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7).
         * @param string      $method       Since 1.1.7
         *
         * @uses fs_ui_get_action_button()
         */
        function fs_ui_action_button(
            $module_id,
            $page,
            $action,
Loading ...