HEX
Server: nginx/1.16.1
System: Linux VM-0-14-centos 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1000)
PHP: 8.3.31
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/www.sceybwg.com/wp-content/plugins/templately/includes/Builder/Managers/Cache.php
<?php

namespace Templately\Builder\Managers;

use Templately\Builder\Source;
use Templately\Builder\Types\ThemeTemplate;
use WP_Query;

class Cache {
	const OPTION_NAME = 'templately_builder_conditions';

	protected $conditions = [];

	public function __construct() {
		$this->refresh();
	}

	public function refresh(): Cache {
		$this->conditions = get_option( self::OPTION_NAME, [] );

		return $this;
	}

	/**
	 * @param  $document
	 * @param array $conditions
	 *
	 * @return $this
	 */
	public function update( $document, array $conditions ): Cache {
		return $this->remove( $document->get_main_id() )->add( $document, $conditions );
	}

	/**
	 * @param ThemeTemplate $document
	 * @param array $conditions
	 *
	 * @return $this
	 */
	public function add( ThemeTemplate $document, array $conditions ): Cache {
		$location = $document->get_location();
		if ( $location ) {
			if ( ! isset( $this->conditions[ $location ] ) ) {
				$this->conditions[ $location ] = [];
			}
			$this->conditions[ $location ][ $document->get_main_id() ] = $conditions;
		}

		return $this;
	}

	/**
	 * @param int $post_id
	 *
	 * @return $this
	 */
	public function remove( int $post_id ): Cache {
		$post_id = absint( $post_id );

		foreach ( $this->conditions as $location => $templates ) {
			foreach ( $templates as $id => $template ) {
				if ( $post_id === $id ) {
					unset( $this->conditions[ $location ][ $id ] );
				}
			}
		}

		return $this;
	}

	public function save(): bool {
		return update_option( self::OPTION_NAME, $this->conditions );
	}

	public function clear(): Cache {
		$this->conditions = [];

		return $this;
	}

	public function get_by_location( $location ) {
		if ( isset( $this->conditions[ $location ] ) ) {
			return $this->conditions[ $location ];
		}

		return [];
	}

	public function regenerate(): Cache {
		$this->clear();

		$query_args = [
			'posts_per_page' => - 1,
			'post_type'      => Source::CPT,
			'fields'         => 'ids',
			'meta_key'       => '_templately_conditions',
		];

		$query = new WP_Query( $query_args );

		foreach ( $query->posts as $post_id ) {
			$document = templately()->theme_builder->get_template( $post_id );

			if ( $document ) {
				$conditions = $document->get_meta( '_templately_conditions' );
				$this->add( $document, $conditions );
			}
		}

		$this->save();

		return $this;
	}
}