HEX
HEX
Server: Apache
System: Linux localhost.localdomain 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1001)
PHP: 8.1.32
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/ahmsolaiman.com/wp-content/plugins/types/application/models/field/group/view/Group.php
<?php

namespace OTGS\Toolset\Types\Field\Group\View;

use DateInterval;
use DateTime;
use Exception;
use WP_Post;

/**
 * View helper for field group
 *
 * @since 3.2
 */
class Group {

	/** @var array */
	private $group;

	/** @var WP_Post|null */
	private $group_post;


	/**
	 * Collapsed constructor.
	 *
	 * @param array $group Legacy array structure, take it with care and proof every key pre-use.
	 * @param WP_Post|null $group_post
	 */
	public function __construct( $group, WP_Post $group_post = null ) {
		$this->group = $group;
		$this->group_post = $group_post;
	}


	/**
	 * Check if group settings are collapsed
	 */
	public function are_settings_collapsed() {
		if ( ! is_array( $this->group ) ) {
			return false;
		}

		if ( ! isset( $this->group['id'] ) || empty( $this->group['id'] ) ) {
			// new group -> not collapsed
			return false;
		}

		if ( ! isset( $this->group['fields'] )
			|| ! is_array( $this->group['fields'] )
			|| empty( $this->group['fields'] ) ) {
			// no field created yet -> not collapsed
			return false;
		}

		if ( ! $this->group_post ) {
			// for further checks the group post is required, if not show the settings
			return false;
		}

		// get creation time of group to compare with current time
		try {
			$post_created = new DateTime( $this->group_post->post_date );
			$now = new DateTime( 'now' );
		} catch ( Exception $e ) {
			return false;
		}


		if ( $post_created->add( new DateInterval( 'PT10M' ) ) > $now ) {
			// group is not older than an 10 minutes -> not collapsed
			return false;
		}

		// group has fields and is older than 10 minutes
		// in this case the group should be collapsed on load
		return true;
	}
}