Skip to content

Commit

Permalink
fix: add View loader class
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Waldstein committed Aug 15, 2023
1 parent 8adc133 commit 1983711
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 8 deletions.
8 changes: 4 additions & 4 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Description: The most robust, flexible, and intuitive way to accept donations on WordPress.
* Author: GiveWP
* Author URI: https://givewp.com/
* Version: 2.32.0
* Requires at least: 5.0
* Requires PHP: 7.0
* Version: 3.0.0
* Requires at least: 5.9
* Requires PHP: 7.2
* Text Domain: give
* Domain Path: /languages
*
Expand Down Expand Up @@ -330,7 +330,7 @@ private function setup_constants()
{
// Plugin version.
if (!defined('GIVE_VERSION')) {
define('GIVE_VERSION', '2.32.0');
define('GIVE_VERSION', '3.0.0');
}

// Plugin Root File.
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Contributors: givewp, dlocc, webdevmattcrom, ravinderk, mehul0810, kevinwhoffman, jason_the_adams, henryholtgeerts, kbjohnson90, alaca, benmeredithgmailcom, jonwaldstein, joshuadinh, glaubersilvawp, pauloiankoski
Donate link: https://go.givewp.com/home
Tags: donation, donate, recurring donations, fundraising, crowdfunding
Requires at least: 5.0
Requires at least: 5.9
Tested up to: 6.3
Requires PHP: 7.0
Stable tag: 2.32.0
Requires PHP: 7.2
Stable tag: 3.0.0
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -258,6 +258,9 @@ The 2% fee on Stripe donations only applies to donations taken via our free Stri
8. GiveWP has a dedicated support team to help answer any questions you may have and help you through stumbling blocks.

== Changelog ==
= 3.0.0: August 15th, 2023 =
* New: GiveWP 3.0 is here! This is a major release that includes a new visual form builder and many more. Read more about it [on our website](https://go.givewp.com/corenextgen).

= 2.32.0: August 11th, 2023 =
* Feature: Scroll Stripe modal into view for Legacy + Multi-step forms
* Feature: Added check for application/json in form headers accept
Expand Down
3 changes: 2 additions & 1 deletion src/FormBuilder/Routes/RegisterFormBuilderPageRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Give\FormBuilder\Routes;

use Give\Addon\View;

use Give\FormBuilder\FormBuilderRouteBuilder;
use Give\FormBuilder\ViewModels\FormBuilderViewModel;
use Give\Framework\EnqueueScript;
use Give\Framework\Views\View;
use Give\Helpers\Hooks;
use Give\Log\Log;

Expand Down
88 changes: 88 additions & 0 deletions src/Framework/Views/View.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Give\Framework\Views;

use InvalidArgumentException;

/**
* Helper class responsible for loading views.
*/
class View
{
/**
* Default domain
*/
const DEFAULT_DOMAIN = 'FormBuilder';

/**
* @since 3.0.0
*
* @param array $templateParams Arguments for template.
* @param bool $echo
*
* @param string $view Template name
* When using multiple domains within this plugin, the domain directory can be set by using "." in the template name.
* String before the "." character is domain directory, and everything after is the template file path
* Example usage: View::render( 'DomainName.templateName' );
* This will try to load src/DomainName/resources/view/templateName.php file
*
* @return string|void
* @throws InvalidArgumentException if template file not exist
*
*/
public static function load($view, $templateParams = [], $echo = false)
{
// Get domain and file path
list ($domain, $file) = static::getPaths($view);
$template = GIVE_PLUGIN_DIR . "src/{$domain}/resources/views/{$file}.php";

if ( ! file_exists($template)) {
throw new InvalidArgumentException("View template file {$template} does not exist");
}

ob_start();
extract($templateParams);
include $template;
$content = ob_get_clean();

if ( ! $echo) {
return $content;
}

echo $content;
}

/**
* @since 3.0.0
*
* @param array $vars
*
* @param string $view
*/
public static function render($view, $vars = [])
{
static::load($view, $vars, true);
}

/**
* Get domain and template file path
*
* @since 3.0.0
*
* @param string $path
*
* @return array
*/
private static function getPaths($path)
{
// Check for . delimiter
if (false === strpos($path, '.')) {
return [
self::DEFAULT_DOMAIN,
$path,
];
}

return explode('.', $path, 2);
}
}

0 comments on commit 1983711

Please sign in to comment.