GRAYBYTE WORDPRESS FILE MANAGER7248

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /home/giriqfky/trustyourlawyer.com/wp-content/plugins/essential-blocks/includes/API/
Upload Files :
Current_dir [ Writeable ] Document_root [ Writeable ]

Command :


Current File : /home/giriqfky/trustyourlawyer.com/wp-content/plugins/essential-blocks/includes/API//PostBlock.php
<?php

namespace EssentialBlocks\API;

use EssentialBlocks\Utils\Helper;
use EssentialBlocks\Blocks\PostGrid as PostGridBlock;
use EssentialBlocks\Blocks\PostCarousel as PostCarouselBlock;

class PostBlock extends Base
{
    /**
     * Register REST Routes
     * @return void
     */
    public function register()
    {
        $this->get( 'queries', [
            'callback' => [ $this, 'get_posts' ]
         ] );
    }

    public function get_posts( $request )
    {
        $block_type = $request->has_param( 'block_type' ) ? $request->get_param( 'block_type' ) : 'post-grid';

        if ( ! isset( $request[ 'query_data' ] ) || ! $request[ 'attributes' ] ) {
            wp_send_json_error( "Invalid request param" );
        }
        $query      = json_decode( $request[ 'query_data' ], true );
        $attributes = json_decode( $request[ 'attributes' ], true );
        $query      = ( is_object( $query ) || is_array( $query ) ) ? (array) $query : [  ];
        $attributes = ( is_object( $attributes ) || is_array( $attributes ) ) ? (array) $attributes : [  ];
        $pageNumber = isset( $request[ 'pageNumber' ] ) ? (int) sanitize_text_field( $request[ 'pageNumber' ] ) - 1 : 0;
        //Check if param is empty
        if ( ! is_array( $query ) || ! is_array( $attributes ) ) {
            wp_send_json_error( "Invalid request param" );
        }

        if ( isset( $query[ 'per_page' ] ) && isset( $query[ 'offset' ] ) ) {
            $query[ 'offset' ] = (int) $query[ 'offset' ] + ( (int) $query[ 'per_page' ] * (int) $pageNumber );
        }

        $_template_name = 'carousel-markup';
        $block_object   = PostCarouselBlock::get_instance();
        if ( $block_type === 'post-grid' ) {
            if ( isset( $request[ "taxonomy" ] ) && isset( $request[ "category" ] ) ) {
                $category  = get_term_by( 'slug', sanitize_text_field( $request[ "category" ] ), sanitize_text_field( $request[ "taxonomy" ] ) );
                $catString = wp_json_encode( [ [
                    "label" => $category->name,
                    "value" => $category->term_id
                 ] ] );
                $filterQuery = [
                    $request[ "taxonomy" ] => [
                        "name"  => sanitize_text_field( $request[ "category" ] ),
                        "slug"  => sanitize_text_field( $request[ "category" ] ),
                        "value" => $catString
                     ]
                 ];
                $query[ "taxonomies" ] = array_merge( $query[ 'taxonomies' ] ?? [  ], $filterQuery );
            }

            if ( isset( $request[ "query_type" ] ) && $request[ "query_type" ] == 'search' && isset( $request[ "s" ] ) ) {
                $searchKey    = sanitize_text_field( $request[ "s" ] );
                $query[ "s" ] = $searchKey;
            }

            $_template_name = 'grid-markup';
            $block_object   = PostGridBlock::get_instance();
            $attributes     = wp_parse_args( $attributes, $block_object->get_default_attributes() );
        }

        $result = $block_object->get_posts( $query, true );
        $posts  = [  ];
        if ( isset( $result->posts ) && is_array( $result->posts ) && count( $result->posts ) > 0 ) {
            $posts = $result->posts;
        }
        $posts_count = 0;
        if ( isset( $result->found_posts ) ) {
            $posts_count = $result->found_posts;
        }

        if ( empty( $posts ) ) {
            return false;
        }

        ob_start();
        Helper::views( 'post-partials/' . $_template_name, array_merge( $attributes, [
            'posts'        => $posts,
            'block_object' => $block_object,
            'source'       => isset( $query[ 'source' ] ) ? $query[ 'source' ] : 'post',
            'headerMeta'   => ! empty( $attributes[ 'headerMeta' ] ) ? json_decode( $attributes[ 'headerMeta' ] ) : [  ],
            'footerMeta'   => ! empty( $attributes[ 'footerMeta' ] ) ? json_decode( $attributes[ 'footerMeta' ] ) : [  ]
         ] ) );

        $response = rest_ensure_response( ob_get_clean() );
        $response->set_headers( [
            'x-wp-total' => $posts_count
         ] );

        return $response;
    }
}

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
July 10 2025 04:32:25
giriqfky / giriqfky
0755
.htaccess
0.41 KB
July 10 2025 04:32:25
giriqfky / giriqfky
0644
Base.php
1.032 KB
December 05 2023 17:06:42
giriqfky / giriqfky
0644
Common.php
0.529 KB
May 19 2025 15:07:08
giriqfky / giriqfky
0644
PostBlock.php
4.108 KB
January 12 2025 17:13:54
giriqfky / giriqfky
0644
Product.php
16.094 KB
January 12 2025 17:13:54
giriqfky / giriqfky
0644
Server.php
0.532 KB
May 19 2025 15:07:08
giriqfky / giriqfky
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF