Plugin Directory

Changeset 3069513


Ignore:
Timestamp:
04/12/2024 10:33:46 AM (2 years ago)
Author:
appfulapp
Message:

Better mutli-lang support

Location:
appful-app
Files:
7 deleted
15 edited
322 copied

Legend:

Unmodified
Added
Removed
  • appful-app/tags/3.1.25/appful-app.php

    r3053321 r3069513  
    1212 * Plugin URI:        https://appful.io
    1313 * Description:       Appful® is the number 1 plugin for turning your WordPress Content into a native, beautiful app on iOS & Android in under 5 minutes.
    14  * Version:           3.1.24
     14 * Version:           3.1.25
    1515 * Requires at least: 5.8
    1616 * Requires PHP:      7.4
  • appful-app/tags/3.1.25/includes/api/Api.php

    r3027388 r3069513  
    99
    1010class Api {
    11     private ReqHandler $api_request_handler;
     11    private ReqHandler $api_request_handler;
    1212
    13     public function __construct( ReqHandler $api_request_handler ) {
    14         $this->api_request_handler = $api_request_handler;
    15     }
     13    public function __construct( ReqHandler $api_request_handler ) {
     14        $this->api_request_handler = $api_request_handler;
     15    }
    1616
    17     public function init() {
    18         add_action(
    19             "wp",
    20             function () {
    21                 $this->handle_request();
    22             },
    23             10,
    24         );
    25     }
     17    public function init() {
     18        add_action(
     19            "wp",
     20            function () {
     21                $this->handle_request();
     22            },
     23            10,
     24        );
     25    }
    2626
    27     private function handle_request() {
    28         if ( get_query_var( "appful", 0 ) != 0 ) {
    29             $action = get_query_var( "appful_action" );
    30             Logger::debug( "Handling WP Plugin request from Appful, action: " . $action );
     27    private function handle_request() {
     28        if ( get_query_var( "appful", 0 ) != 0 ) {
     29            $action = get_query_var( "appful_action" );
     30            Logger::debug( "Handling WP Plugin request from Appful, action: " . $action );
    3131
    32             $request = PluginRequest::plugin_request()->action( $action );
    33             if ( $request->requires_auth() ) {
    34                 $token  = $this->parse_token();
    35                 $request = $request->token( $token );
    36             }
    37             $response = $this->api_request_handler->handle_request( $request );
     32            $request = PluginRequest::plugin_request()->action( $action );
     33            if ( $request->requires_auth() ) {
     34                $token = $this->parse_token();
     35                $request = $request->token( $token );
     36            }
     37            $response = $this->api_request_handler->handle_request( $request );
    3838
    39             $this->respond( $response );
    40         }
    41     }
     39            $this->respond( $response );
     40        }
     41    }
    4242
    43     private function parse_token(): ?string {
    44         $token = null;
     43    private function parse_token(): ?string {
     44        $token = null;
    4545
    46         $header = $_SERVER['HTTP_AUTHORIZATION'] ?? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ?? null;
    47         if ( $header != null && 0 === stripos( $header, "Bearer " ) ) {
    48             $token = sanitize_text_field( substr( $header, strlen( "Bearer " ) ) );
    49         }
     46        $header = $_SERVER['HTTP_AUTHORIZATION'] ?? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ?? null;
     47        if ( $header != null && 0 === stripos( $header, "Bearer " ) ) {
     48            $token = sanitize_text_field( substr( $header, strlen( "Bearer " ) ) );
     49        }
    5050
    51         if ( $token == null ) {
    52             $this->unauthorized();
    53         }
     51        if ( $token == null ) {
     52            $this->unauthorized();
     53        }
    5454
    55         $current_session_id = ClientTokenManager::getToken();
    56         if ( $current_session_id == null ) {
    57             $this->notAvailable();
    58         }
    59         if ( strcmp( $token, $current_session_id ) != 0 ) {
    60             $this->unauthorized();
    61         }
     55        $current_session_id = ClientTokenManager::getToken();
     56        if ( $current_session_id == null ) {
     57            $this->notAvailable();
     58        }
     59        if ( strcmp( $token, $current_session_id ) != 0 ) {
     60            $this->unauthorized();
     61        }
    6262
    63         return $token;
    64     }
     63        return $token;
     64    }
    6565
    66     private function unauthorized() {
    67         $this->respond( PluginResponse::plugin_response()->status( 401 ) );
    68     }
     66    private function unauthorized() {
     67        $this->respond( PluginResponse::plugin_response()->status( 401 ) );
     68    }
    6969
    70     private function respond( PluginResponse $response ) {
    71         ob_end_clean();
    72         if ( $response->get_encoded() ) {
    73             header( "Content-Type: application/json" );
    74         }
    75         status_header( $response->get_status() );
    76         exit( $response->get_body() );
    77     }
     70    private function respond( PluginResponse $response ) {
     71        while (ob_get_level() > 0) {
     72            ob_end_clean();
     73        }
     74        if ( $response->get_encoded() ) {
     75            header( "Content-Type: application/json" );
     76        }
     77        status_header( $response->get_status() );
     78        exit( $response->get_body() );
     79    }
    7880
    79     private function notAvailable() {
    80         $this->respond( PluginResponse::plugin_response()->status( 503 ) );
    81     }
     81    private function notAvailable() {
     82        $this->respond( PluginResponse::plugin_response()->status( 503 ) );
     83    }
    8284}
  • appful-app/tags/3.1.25/includes/api/ReqHandler.php

    r3043568 r3069513  
    7474            new GetPageContentsRequestHandler( $use_case_manager->pages()->get_page_contents_by_id_use_case() ),
    7575            new PullLocalPageContentRequestHandler( $use_case_manager->pages()->get_local_page_content_by_id_use_case() ),
    76             new GetPageContentRequestHandler( $use_case_manager->pages()->get_page_contents_by_id_use_case() ),
     76            new GetPageContentRequestHandler( $use_case_manager->pages()->pull_local_page_content_use_case() ),
    7777            new PointOfInterestSyncRequestHandler( $use_case_manager->points_of_interest()->get_sync_points_of_interest_use_case() ),
    7878            new GetPointsOfInterestRequestHandler( $use_case_manager->points_of_interest()->get_get_points_of_interest_by_id_use_case() ),
  • appful-app/tags/3.1.25/includes/api/handlers/page/GetPageContentRequestHandler.php

    r3018629 r3069513  
    99use AppfulPlugin\Api\Responses\PluginResponse;
    1010use AppfulPlugin\Helper\Logger;
    11 use AppfulPlugin\UseCases\Page\GetPageContentsByIdUseCase;
     11use AppfulPlugin\UseCases\Page\PullLocalPageContentUseCase;
    1212
    1313class GetPageContentRequestHandler implements RequestHandler {
    14     private GetPageContentsByIdUseCase $get_page_contents_by_id_use_case;
     14    private PullLocalPageContentUseCase $pull_local_page_content_use_case;
    1515
    16     public function __construct(
    17         GetPageContentsByIdUseCase $get_page_contents_by_id_use_case
    18     ) {
    19         $this->get_page_contents_by_id_use_case = $get_page_contents_by_id_use_case;
    20     }
     16    public function __construct(
     17        PullLocalPageContentUseCase $pull_local_page_content_use_case
     18    ) {
     19        $this->pull_local_page_content_use_case = $pull_local_page_content_use_case;
     20    }
    2121
    22     public function can_handle_request( PluginRequest $request ): bool {
    23         return $request->get_action() == Endpoints::$GET_PAGE_CONTENT_HOOK;
    24     }
     22    public function can_handle_request( PluginRequest $request ): bool {
     23        return $request->get_action() == Endpoints::$GET_PAGE_CONTENT_HOOK;
     24    }
    2525
    26     public function handle_request( PluginRequest $request ): PluginResponse {
    27         Logger::debug( "Found handler for Appful request" );
     26    public function handle_request( PluginRequest $request ): PluginResponse {
     27        Logger::debug( "Found handler for Appful request" );
    2828
    29         if ( ! isset( $_GET['id'] ) ) {
    30             return PluginResponse::plugin_response()->status( 400 );
    31         }
     29        if ( !isset( $_GET['id'] ) ) {
     30            return PluginResponse::plugin_response()->status( 400 );
     31        }
    3232
    33         $cleaned_id = absint( sanitize_text_field( $_GET['id'] ) );
     33        $cleaned_id = absint( sanitize_text_field( $_GET['id'] ) );
    3434
    35         $request_user_id = $_GET['user_id'] ?? null;
    36         $cleaned_user_id = null;
    37         if ( $request_user_id ) {
    38             $cleaned_user_id = absint( sanitize_text_field( $request_user_id ) );
    39         }
     35        $request_user_id = $_GET['user_id'] ?? null;
     36        $cleaned_user_id = null;
     37        if ( $request_user_id ) {
     38            $cleaned_user_id = absint( sanitize_text_field( $request_user_id ) );
     39        }
    4040
    41         Logger::debug( "Sending page content for id " . json_encode( $cleaned_id ) . " for user " . $request_user_id );
     41        Logger::debug( "Sending page content for id " . json_encode( $cleaned_id ) . " for user " . $request_user_id );
    4242
    43         $page_contents = $this->get_page_contents_by_id_use_case->invoke( [ $cleaned_id ], $cleaned_user_id );
    44         if ( count( $page_contents ) == 1 ) {
    45             return PluginResponse::plugin_response()->body( PageContentMapper::to_dto( $page_contents[0] ) );
    46         } else {
    47             return PluginResponse::plugin_response()->status( 404 );
    48         }
    49     }
     43        $page_content = $this->pull_local_page_content_use_case->invoke( $cleaned_id, $cleaned_user_id );
     44        if ( $page_content != null ) {
     45            return PluginResponse::plugin_response()->body( PageContentMapper::to_dto( $page_content ) );
     46        } else {
     47            return PluginResponse::plugin_response()->status( 404 );
     48        }
     49    }
    5050}
  • appful-app/tags/3.1.25/includes/use_cases/PullLocalPostContentUseCase.php

    r3018629 r3069513  
    1010
    1111class PullLocalPostContentUseCase {
    12     private SelfClient $self_client;
     12    private SelfClient $self_client;
    1313
    14     public function __construct( SelfClient $self_client ) {
    15         $this->self_client = $self_client;
    16     }
     14    public function __construct( SelfClient $self_client ) {
     15        $this->self_client = $self_client;
     16    }
    1717
    18     public function invoke( int $id ): ?PostContent {
    19         Logger::debug( "Pulling local post content for id: " . $id );
     18    public function invoke( int $id ): ?PostContent {
     19        Logger::debug( "Pulling local post content for id: " . $id );
    2020
    21         $request_params = [];
     21        $request_params = [];
    2222
    23         $request_params['id'] = $id;
    24         if ( isset( $_REQUEST['debug'] ) && $_REQUEST['debug'] == "1" ) {
    25             $request_params['debug'] = "1";
    26         }
     23        $request_params['id'] = $id;
     24        if ( isset( $_REQUEST['debug'] ) && $_REQUEST['debug'] == "1" ) {
     25            $request_params['debug'] = "1";
     26        }
    2727
    28         $request = HttpRequest::backend_request()->method( "GET" )->path( "/" . Endpoints::$GET_POST_CONTENT_LOCAL )->params( $request_params );
    29         $response = $this->self_client->send_request( $request );
     28        $request = HttpRequest::backend_request()->method( "GET" )->path( "/" . Endpoints::$GET_POST_CONTENT_LOCAL )->params( $request_params );
     29        $response = $this->self_client->send_request( $request );
    3030
    31         if ( $response->get_status() != 200 ) {
    32             return null;
    33         }
     31        if ( $response->get_status() != 200 ) {
     32            return null;
     33        }
    3434
    35         $post_content_dto = $response->get_body();
     35        $post_content_dto = $response->get_body();
    3636
    37         return PostContent::postContent()
    38                           ->id( absint( $post_content_dto["id"] ) )
    39                           ->content( $post_content_dto["content"] )
    40                           ->head( $post_content_dto["head"] )
    41                           ->footer( $post_content_dto["footer"] )
    42                           ->body_class( $post_content_dto["body_class"] );
    43     }
     37        if ( $post_content_dto == null ) {
     38            return null;
     39        }
     40
     41        return PostContent::postContent()
     42            ->id( absint( $post_content_dto["id"] ) )
     43            ->content( $post_content_dto["content"] )
     44            ->head( $post_content_dto["head"] )
     45            ->footer( $post_content_dto["footer"] )
     46            ->body_class( $post_content_dto["body_class"] );
     47    }
    4448}
  • appful-app/tags/3.1.25/includes/use_cases/page/GetPageContentsByIdUseCase.php

    r2978062 r3069513  
    44
    55use AppfulPlugin\Domain\PageContent;
    6 use AppfulPlugin\Wp\WPPageManager;
    76
    87class GetPageContentsByIdUseCase {
    9     private PullLocalPageContentUseCase $pull_local_page_content_use_case;
     8    private PullLocalPageContentUseCase $pull_local_page_content_use_case;
    109
    11     public function __construct( PullLocalPageContentUseCase $pull_local_page_content_use_case ) {
    12         $this->pull_local_page_content_use_case = $pull_local_page_content_use_case;
    13     }
     10    public function __construct( PullLocalPageContentUseCase $pull_local_page_content_use_case ) {
     11        $this->pull_local_page_content_use_case = $pull_local_page_content_use_case;
     12    }
    1413
    15     /**
    16     * @param int[] $ids
    17     *
    18     * @return PageContent[]
    19     */
    20     public function invoke( array $ids, ?int $user_id = null ): array {
    21         $page_contents = [];
     14    /**
     15    * @param int[] $ids
     16    *
     17    * @return PageContent[]
     18    */
     19    public function invoke( array $ids, ?int $user_id = null ): array {
     20        $page_contents = [];
    2221
    23         $page_contents = WPPageManager::get_page_contents_by_ids($ids, $user_id);
    24 //      Uncomment if for some reason fetching all pages at once should not work
    25 //      foreach ( $ids as $page_id ) {
    26 //          $response = $this->pull_local_page_content_use_case->invoke( $page_id, $user_id );
    27 //          if ( $response != null ) {
    28 //              $page_contents[] = $response;
    29 //          }
    30 //      }
     22        foreach ($ids as $page_id) {
     23            $response = $this->pull_local_page_content_use_case->invoke( $page_id, $user_id );
     24            if ( $response != null ) {
     25                $page_contents[] = $response;
     26            }
     27        }
    3128
    32         return $page_contents;
    33     }
     29        return $page_contents;
     30    }
    3431}
  • appful-app/tags/3.1.25/includes/use_cases/page/PullLocalPageContentUseCase.php

    r3018629 r3069513  
    1010
    1111class PullLocalPageContentUseCase {
    12     private SelfClient $self_client;
     12    private SelfClient $self_client;
    1313
    14     public function __construct( SelfClient $self_client ) {
    15         $this->self_client = $self_client;
    16     }
     14    public function __construct( SelfClient $self_client ) {
     15        $this->self_client = $self_client;
     16    }
    1717
    18     public function invoke( int $id, ?int $user_id = null ): ?PageContent {
    19         Logger::debug( "Pulling local page content for id " . $id . " for user " . $user_id );
     18    public function invoke( int $id, ?int $user_id = null ): ?PageContent {
     19        Logger::debug( "Pulling local page content for id " . $id . " for user " . $user_id );
    2020
    21         $request_params = [];
     21        $request_params = [];
    2222
    23         $request_params['id'] = $id;
    24         if ( isset( $_REQUEST['debug'] ) && $_REQUEST['debug'] == "1" ) {
    25             $request_params['debug'] = "1";
    26         }
    27         if ( $user_id ) {
    28             $request_params['user_id'] = $user_id;
    29         }
     23        $request_params['id'] = $id;
     24        if ( isset( $_REQUEST['debug'] ) && $_REQUEST['debug'] == "1" ) {
     25            $request_params['debug'] = "1";
     26        }
     27        if ( $user_id ) {
     28            $request_params['user_id'] = $user_id;
     29        }
    3030
    31         $request = HttpRequest::backend_request()->method( "GET" )->path( "/" . Endpoints::$GET_PAGE_CONTENT_LOCAL )->params( $request_params );
    32         $response = $this->self_client->send_request( $request );
     31        $request = HttpRequest::backend_request()->method( "GET" )->path( "/" . Endpoints::$GET_PAGE_CONTENT_LOCAL )->params( $request_params );
     32        $response = $this->self_client->send_request( $request );
    3333
    34         if ( $response->get_status() != 200 ) {
    35             return null;
    36         }
     34        if ( $response->get_status() != 200 ) {
     35            return null;
     36        }
    3737
    38         $page_content_dto = $response->get_body();
     38        $page_content_dto = $response->get_body();
    3939
    40         return PageContent::pageContent()
    41                           ->id( absint( $page_content_dto["id"] ) )
    42                           ->content( $page_content_dto["content"] )
    43                           ->head( $page_content_dto["head"] )
    44                           ->footer( $page_content_dto["footer"] )
    45                           ->body_class( $page_content_dto["body_class"] );
    46     }
     40        if ( $page_content_dto == null ) {
     41            return null;
     42        }
     43
     44        return PageContent::pageContent()
     45            ->id( absint( $page_content_dto["id"] ) )
     46            ->content( $page_content_dto["content"] )
     47            ->head( $page_content_dto["head"] )
     48            ->footer( $page_content_dto["footer"] )
     49            ->body_class( $page_content_dto["body_class"] );
     50    }
    4751}
  • appful-app/tags/3.1.25/includes/wp/WPAttachmentManager.php

    r3019874 r3069513  
    9696        ];
    9797
    98         $all_attachments = get_posts( $args );
     98        $all_attachments = LanguageHelper::for_each_language( function () use ( $args ) {
     99            return get_posts( $args );
     100        } );
    99101
    100102        $all_attachments = array_values(
  • appful-app/tags/3.1.25/includes/wp/WPCommentDatabaseManager.php

    r3019874 r3069513  
    2525        global $wpdb;
    2626
    27         $query = $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments AS comment" );
    28 
    29         return $wpdb->get_var( $query );
     27        return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments" );
    3028    }
    3129}
  • appful-app/tags/3.1.25/includes/wp/WPCommentManager.php

    r3019874 r3069513  
    1212
    1313class WPCommentManager {
    14     public static function get_comment_count(): int {
    15         return WPCommentDatabaseManager::get_count();
    16     }
     14    public static function get_comment_count(): int {
     15        return WPCommentDatabaseManager::get_count();
     16    }
    1717
    18     /** @return SyncItem[] */
    19     public static function get_comment_sync_items( int $offset, int $count ): array {
    20         return WPCommentDatabaseManager::get_sync_items( $count, $offset );
    21     }
     18    /** @return SyncItem[] */
     19    public static function get_comment_sync_items( int $offset, int $count ): array {
     20        return WPCommentDatabaseManager::get_sync_items( $count, $offset );
     21    }
    2222
    23     /**
    24     * @param int[] $ids
    25     *
    26     * @return Comment[]
    27     */
    28     public static function get_comments_by_id( array $ids ): array {
    29         $args = [
    30             "status"      => array_keys( get_comment_statuses() ),
    31             "comment__in" => $ids
    32         ];
     23    /**
     24    * @param int[] $ids
     25    *
     26    * @return Comment[]
     27    */
     28    public static function get_comments_by_id( array $ids ): array {
     29        $args = [
     30            "status" => array_keys( get_comment_statuses() ),
     31            "comment__in" => $ids
     32        ];
    3333
    34         $all_comments = LanguageHelper::for_each_language( function () use ( $args ) {
    35             return get_comments( $args );
    36         } );
     34        $all_comments = LanguageHelper::for_each_language( function () use ( $args ) {
     35            return get_comments( $args );
     36        } );
    3737
    38         return array_map(
    39             function ( WP_Comment $comment ) {
    40                 return CommentMapper::to_domain( $comment );
    41             },
    42             $all_comments
    43         );
    44     }
     38        return array_map(
     39            function ( WP_Comment $comment ) {
     40                return CommentMapper::to_domain( $comment );
     41            },
     42            $all_comments
     43        );
     44    }
    4545
    46     public static function create_comment( CreateCommentRequest $request ): ?Comment {
    47         $commentData = [
    48             'comment_author'      => $request->get_username(), // The name of the author of the comment.
    49             'comment_author_email' => $request->get_email(), // The email address of the $comment_author.
    50             'comment_content'      => $request->get_content(), // The content of the comment.
    51             'comment_post_ID'      => $request->get_post_id(), // ID of the post that relates to the comment.
    52             'comment_parent'      => $request->get_parent_id(), // ID of this comment's parent, if any.
    53         ];
     46    public static function create_comment( CreateCommentRequest $request ): ?Comment {
     47        $commentData = [
     48            'comment_author' => $request->get_username(), // The name of the author of the comment.
     49            'comment_author_email' => $request->get_email(), // The email address of the $comment_author.
     50            'comment_content' => $request->get_content(), // The content of the comment.
     51            'comment_post_ID' => $request->get_post_id(), // ID of the post that relates to the comment.
     52            'comment_parent' => $request->get_parent_id(), // ID of this comment's parent, if any.
     53        ];
    5454
    55         $commentId = wp_insert_comment( $commentData );
     55        $commentId = wp_insert_comment( $commentData );
    5656
    57         if ( $commentId === false ) {
    58             Logger::error( "Insert comment failed" );
     57        if ( $commentId === false ) {
     58            Logger::error( "Insert comment failed" );
    5959
    60             return null;
    61         }
     60            return null;
     61        }
    6262
    63         $comment = get_comment( $commentId );
     63        $comment = get_comment( $commentId );
    6464
    65         if ( ! $comment instanceof WP_Comment ) {
    66             Logger::error( "Getting comment failed!" );
     65        if ( !$comment instanceof WP_Comment ) {
     66            Logger::error( "Getting comment failed!" );
    6767
    68             return null;
    69         }
     68            return null;
     69        }
    7070
    71         return CommentMapper::to_domain( $comment );
    72     }
     71        return CommentMapper::to_domain( $comment );
     72    }
    7373}
  • appful-app/tags/3.1.25/includes/wp/WPPageManager.php

    r3019874 r3069513  
    1111
    1212class WPPageManager {
    13     public static function get_page_permalink( WP_Post $page ): ?string {
    14         return get_permalink( $page );
    15     }
     13    public static function get_page_permalink( WP_Post $page ): ?string {
     14        return get_permalink( $page );
     15    }
    1616
    17     public static function get_page_language( int $page_id ): string {
    18         return LanguageHelper::get_page_language( $page_id );
    19     }
     17    public static function get_page_language( int $page_id ): string {
     18        return LanguageHelper::get_page_language( $page_id );
     19    }
    2020
    21     public static function get_page_count(): int {
    22         return WPPostDatabaseManager::get_count_for_type( "page" );
    23     }
     21    public static function get_page_count(): int {
     22        return WPPostDatabaseManager::get_count_for_type( "page" );
     23    }
    2424
    25     /** @return SyncItem[] */
    26     public static function get_page_sync_items( int $offset, int $count ): array {
    27         return WPPostDatabaseManager::get_sync_items_for_type( "page", $count, $offset );
    28     }
     25    /** @return SyncItem[] */
     26    public static function get_page_sync_items( int $offset, int $count ): array {
     27        return WPPostDatabaseManager::get_sync_items_for_type( "page", $count, $offset );
     28    }
    2929
    30     /**
    31      * @param int[] $ids
    32      *
    33      * @return Page[]
    34      */
    35     public static function get_pages_by_id( array $ids ): array {
    36         $args = [
    37             "numberposts" => - 1,
    38             "post_status" => self::get_allowed_page_stati()
    39         ];
     30    /**
     31     * @param int[] $ids
     32     *
     33     * @return Page[]
     34     */
     35    public static function get_pages_by_id( array $ids ): array {
     36        $args = [
     37            "numberposts" => -1,
     38            "include" => $ids,
     39            "post_status" => self::get_allowed_page_stati()
     40        ];
    4041
    41         $all_pages = get_pages( $args );
     42        $all_pages = LanguageHelper::for_each_language( function () use ( $args ) {
     43            return get_pages( $args );
     44        } );
    4245
    43         $all_pages = array_values(
    44             array_filter( $all_pages, function ( WP_Post $page ) use ( $ids ) {
    45                 return in_array( $page->ID, $ids );
    46             } )
    47         );
     46        $all_pages = array_values(
     47            array_filter( $all_pages, function ( WP_Post $page ) use ( $ids ) {
     48                return in_array( $page->ID, $ids );
     49            } )
     50        );
    4851
    49         return array_map(
    50             function ( WP_Post $page ) {
    51                 return PageMapper::to_domain( $page );
    52             },
    53             $all_pages
    54         );
    55     }
     52        return array_map(
     53            function ( WP_Post $page ) {
     54                return PageMapper::to_domain( $page );
     55            },
     56            $all_pages
     57        );
     58    }
    5659
    57     public static function get_page_content_by_id( int $id, ?int $user_id = null ): ?PageContent {
    58         global $wp_query;
     60    public static function get_page_content_by_id( int $id, ?int $user_id = null ): ?PageContent {
     61        if ( $user_id ) {
     62            wp_set_current_user( $user_id );
     63        }
    5964
    60         if ( $user_id ) {
    61             wp_set_current_user( $user_id );
    62         }
     65        $args = [
     66            "posts_per_page" => 1,
     67            "post_type" => "page",
     68            "p" => $id,
     69            "post_status" => self::get_allowed_page_stati()
     70        ];
    6371
    64         $args = [
    65             "posts_per_page" => 1,
    66             "post_type"      => "page",
    67             "p"              => $id,
    68             "post_status"    => self::get_allowed_page_stati()
    69         ];
     72        $page_language = self::get_page_language( $id );
     73        return LanguageHelper::for_language(
     74            $page_language,
     75            function () use ( $args ) {
     76                global $wp_query;
    7077
    71         $wp_query = new \WP_Query( $args );
     78                do_action( 'template_redirect' );
    7279
    73         do_action( 'template_redirect' );
     80                $wp_query = new \WP_Query( $args );
    7481
    75         if ( have_posts() ) {
    76             the_post();
     82                if ( have_posts() ) {
     83                    the_post();
    7784
    78             ob_start();
    79             wp_head();
    80             $head = ob_get_clean();
     85                    ob_start();
     86                    wp_head();
     87                    $head = ob_get_clean();
    8188
    82             ob_start();
    83             the_content();
    84             $content = ob_get_clean();
     89                    ob_start();
     90                    the_content();
     91                    $content = ob_get_clean();
    8592
    86             ob_start();
    87             wp_footer();
    88             $footer = ob_get_clean();
     93                    ob_start();
     94                    wp_footer();
     95                    $footer = ob_get_clean();
    8996
    90             ob_start();
    91             body_class();
    92             $body_class = ob_get_clean();
     97                    ob_start();
     98                    body_class();
     99                    $body_class = ob_get_clean();
    93100
    94             wp_reset_postdata();
     101                    wp_reset_postdata();
    95102
    96             return PageContent::pageContent()
    97                               ->id( get_the_ID() )
    98                               ->content( $content )
    99                               ->head( $head )
    100                               ->footer( $footer )
    101                               ->body_class( $body_class );
    102         }
     103                    return PageContent::pageContent()
     104                        ->id( get_the_ID() )
     105                        ->content( $content )
     106                        ->head( $head )
     107                        ->footer( $footer )
     108                        ->body_class( $body_class );
     109                }
    103110
    104         return null;
    105     }
     111                return null;
     112            }
     113        );
     114    }
    106115
    107     public static function get_page_contents_by_ids( array $ids, ?int $user_id = null ): array {
    108         global $wp_query;
    109 
    110         if ( $user_id ) {
    111             wp_set_current_user( $user_id );
    112         }
    113 
    114         $args = [
    115             "posts_per_page" => - 1,
    116             "post_type"      => "page",
    117             "post__in"       => $ids,
    118             "post_status"    => self::get_allowed_page_stati()
    119         ];
    120 
    121         $wp_query = new \WP_Query( $args );
    122 
    123         do_action( 'template_redirect' );
    124 
    125         $pages = [];
    126 
    127         if ( have_posts() ) {
    128             ob_start();
    129             wp_head();
    130             $head = ob_get_clean();
    131 
    132             ob_start();
    133             body_class();
    134             $body_class = ob_get_clean();
    135 
    136             while ( have_posts() ) {
    137                 the_post();
    138 
    139                 ob_start();
    140                 the_content();
    141                 $content = ob_get_clean();
    142 
    143                 $pages[] = PageContent::pageContent()
    144                                       ->id( get_the_ID() )
    145                                       ->content( $content )
    146                                       ->head( $head )
    147                                       ->footer( "" )
    148                                       ->body_class( $body_class );
    149             }
    150 
    151             ob_start();
    152             wp_footer();
    153             $footer = ob_get_clean();
    154 
    155             $pages = array_map( function ( PageContent $content ) use ( $footer ) {
    156                 return $content->footer( $footer );
    157             }, $pages );
    158         }
    159 
    160         wp_reset_postdata();
    161 
    162         return $pages;
    163     }
    164 
    165     /**
    166      * @return string[]
    167      */
    168     private static function get_allowed_page_stati(): array {
    169         return array_filter( get_post_stati(), function ( string $status ) {
    170             return $status != "auto-draft";
    171         } );
    172     }
     116    /**
     117     * @return string[]
     118     */
     119    private static function get_allowed_page_stati(): array {
     120        return array_filter( get_post_stati(), function ( string $status ) {
     121            return $status != "auto-draft";
     122        } );
     123    }
    173124}
  • appful-app/tags/3.1.25/includes/wp/WPPostManager.php

    r3043568 r3069513  
    131131
    132132    public static function get_post_content_by_id( int $id ): ?PostContent {
    133         global $wp_query;
    134 
    135133        $args = [
    136134            "post_type"   => "post",
     
    139137        ];
    140138
    141         $wp_query = new \WP_Query( $args );
    142 
    143         self::setup_wp_call();
    144 
    145         if ( have_posts() ) {
    146             the_post();
    147 
    148             Logger::debug( "Getting head!" );
    149             $head = self::get_data_code( 'wp_head' );
    150             Logger::debug( "Getting content!" );
    151             $content = self::get_data_code( 'the_content' );
    152             Logger::debug( "Getting footer!" );
    153             $footer = self::get_data_code( 'wp_footer' );
    154             Logger::debug( "Getting body classes!" );
    155             $body_class = self::get_data_code( 'body_class' );
    156 
    157             wp_reset_postdata();
    158 
    159             return PostContent::postContent()
    160                               ->id( get_the_ID() )
    161                               ->content( $content )
    162                               ->head( $head )
    163                               ->footer( $footer )
    164                               ->body_class( $body_class );
    165         }
    166 
    167         return null;
     139        $post_language = self::get_post_language( $id );
     140        return LanguageHelper::for_language(
     141            $post_language,
     142            function() use ( $args ) {
     143                global $wp_query;
     144
     145                $wp_query = new \WP_Query( $args );
     146
     147                self::setup_wp_call();
     148
     149                if ( have_posts() ) {
     150                    the_post();
     151
     152                    Logger::debug( "Getting head!" );
     153                    $head = self::get_data_code( 'wp_head' );
     154                    Logger::debug( "Getting content!" );
     155                    $content = self::get_data_code( 'the_content' );
     156                    Logger::debug( "Getting footer!" );
     157                    $footer = self::get_data_code( 'wp_footer' );
     158                    Logger::debug( "Getting body classes!" );
     159                    $body_class = self::get_data_code( 'body_class' );
     160
     161                    wp_reset_postdata();
     162
     163                    return PostContent::postContent()
     164                        ->id( get_the_ID() )
     165                        ->content( $content )
     166                        ->head( $head )
     167                        ->footer( $footer )
     168                        ->body_class( $body_class );
     169                }
     170
     171                return null;
     172            }
     173        );
    168174    }
    169175
  • appful-app/tags/3.1.25/includes/wp/WPUserDatabaseManager.php

    r3019874 r3069513  
    2525        global $wpdb;
    2626
    27         $query = $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->users AS user" );
    28 
    29         return $wpdb->get_var( $query );
     27        return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
    3028    }
    3129}
  • appful-app/tags/3.1.25/lib/vendor/composer/installed.php

    r3043568 r3069513  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '6f0d2c0f0f21f2ca2550d7a07d32827d416dc20c',
     6        'reference' => '455447cb78389ae33d8dd91f6fcc71f5b36b9f5a',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '6f0d2c0f0f21f2ca2550d7a07d32827d416dc20c',
     16            'reference' => '455447cb78389ae33d8dd91f6fcc71f5b36b9f5a',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
  • appful-app/tags/3.1.25/readme.txt

    r3053321 r3069513  
    66Tested up to: 6.4
    77Requires PHP: 7.4
    8 Stable tag: 3.1.24
     8Stable tag: 3.1.25
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • appful-app/trunk/appful-app.php

    r3053321 r3069513  
    1212 * Plugin URI:        https://appful.io
    1313 * Description:       Appful® is the number 1 plugin for turning your WordPress Content into a native, beautiful app on iOS & Android in under 5 minutes.
    14  * Version:           3.1.24
     14 * Version:           3.1.25
    1515 * Requires at least: 5.8
    1616 * Requires PHP:      7.4
  • appful-app/trunk/includes/api/Api.php

    r3027388 r3069513  
    99
    1010class Api {
    11     private ReqHandler $api_request_handler;
     11    private ReqHandler $api_request_handler;
    1212
    13     public function __construct( ReqHandler $api_request_handler ) {
    14         $this->api_request_handler = $api_request_handler;
    15     }
     13    public function __construct( ReqHandler $api_request_handler ) {
     14        $this->api_request_handler = $api_request_handler;
     15    }
    1616
    17     public function init() {
    18         add_action(
    19             "wp",
    20             function () {
    21                 $this->handle_request();
    22             },
    23             10,
    24         );
    25     }
     17    public function init() {
     18        add_action(
     19            "wp",
     20            function () {
     21                $this->handle_request();
     22            },
     23            10,
     24        );
     25    }
    2626
    27     private function handle_request() {
    28         if ( get_query_var( "appful", 0 ) != 0 ) {
    29             $action = get_query_var( "appful_action" );
    30             Logger::debug( "Handling WP Plugin request from Appful, action: " . $action );
     27    private function handle_request() {
     28        if ( get_query_var( "appful", 0 ) != 0 ) {
     29            $action = get_query_var( "appful_action" );
     30            Logger::debug( "Handling WP Plugin request from Appful, action: " . $action );
    3131
    32             $request = PluginRequest::plugin_request()->action( $action );
    33             if ( $request->requires_auth() ) {
    34                 $token  = $this->parse_token();
    35                 $request = $request->token( $token );
    36             }
    37             $response = $this->api_request_handler->handle_request( $request );
     32            $request = PluginRequest::plugin_request()->action( $action );
     33            if ( $request->requires_auth() ) {
     34                $token = $this->parse_token();
     35                $request = $request->token( $token );
     36            }
     37            $response = $this->api_request_handler->handle_request( $request );
    3838
    39             $this->respond( $response );
    40         }
    41     }
     39            $this->respond( $response );
     40        }
     41    }
    4242
    43     private function parse_token(): ?string {
    44         $token = null;
     43    private function parse_token(): ?string {
     44        $token = null;
    4545
    46         $header = $_SERVER['HTTP_AUTHORIZATION'] ?? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ?? null;
    47         if ( $header != null && 0 === stripos( $header, "Bearer " ) ) {
    48             $token = sanitize_text_field( substr( $header, strlen( "Bearer " ) ) );
    49         }
     46        $header = $_SERVER['HTTP_AUTHORIZATION'] ?? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ?? null;
     47        if ( $header != null && 0 === stripos( $header, "Bearer " ) ) {
     48            $token = sanitize_text_field( substr( $header, strlen( "Bearer " ) ) );
     49        }
    5050
    51         if ( $token == null ) {
    52             $this->unauthorized();
    53         }
     51        if ( $token == null ) {
     52            $this->unauthorized();
     53        }
    5454
    55         $current_session_id = ClientTokenManager::getToken();
    56         if ( $current_session_id == null ) {
    57             $this->notAvailable();
    58         }
    59         if ( strcmp( $token, $current_session_id ) != 0 ) {
    60             $this->unauthorized();
    61         }
     55        $current_session_id = ClientTokenManager::getToken();
     56        if ( $current_session_id == null ) {
     57            $this->notAvailable();
     58        }
     59        if ( strcmp( $token, $current_session_id ) != 0 ) {
     60            $this->unauthorized();
     61        }
    6262
    63         return $token;
    64     }
     63        return $token;
     64    }
    6565
    66     private function unauthorized() {
    67         $this->respond( PluginResponse::plugin_response()->status( 401 ) );
    68     }
     66    private function unauthorized() {
     67        $this->respond( PluginResponse::plugin_response()->status( 401 ) );
     68    }
    6969
    70     private function respond( PluginResponse $response ) {
    71         ob_end_clean();
    72         if ( $response->get_encoded() ) {
    73             header( "Content-Type: application/json" );
    74         }
    75         status_header( $response->get_status() );
    76         exit( $response->get_body() );
    77     }
     70    private function respond( PluginResponse $response ) {
     71        while (ob_get_level() > 0) {
     72            ob_end_clean();
     73        }
     74        if ( $response->get_encoded() ) {
     75            header( "Content-Type: application/json" );
     76        }
     77        status_header( $response->get_status() );
     78        exit( $response->get_body() );
     79    }
    7880
    79     private function notAvailable() {
    80         $this->respond( PluginResponse::plugin_response()->status( 503 ) );
    81     }
     81    private function notAvailable() {
     82        $this->respond( PluginResponse::plugin_response()->status( 503 ) );
     83    }
    8284}
  • appful-app/trunk/includes/api/ReqHandler.php

    r3043568 r3069513  
    7474            new GetPageContentsRequestHandler( $use_case_manager->pages()->get_page_contents_by_id_use_case() ),
    7575            new PullLocalPageContentRequestHandler( $use_case_manager->pages()->get_local_page_content_by_id_use_case() ),
    76             new GetPageContentRequestHandler( $use_case_manager->pages()->get_page_contents_by_id_use_case() ),
     76            new GetPageContentRequestHandler( $use_case_manager->pages()->pull_local_page_content_use_case() ),
    7777            new PointOfInterestSyncRequestHandler( $use_case_manager->points_of_interest()->get_sync_points_of_interest_use_case() ),
    7878            new GetPointsOfInterestRequestHandler( $use_case_manager->points_of_interest()->get_get_points_of_interest_by_id_use_case() ),
  • appful-app/trunk/includes/api/handlers/page/GetPageContentRequestHandler.php

    r3018629 r3069513  
    99use AppfulPlugin\Api\Responses\PluginResponse;
    1010use AppfulPlugin\Helper\Logger;
    11 use AppfulPlugin\UseCases\Page\GetPageContentsByIdUseCase;
     11use AppfulPlugin\UseCases\Page\PullLocalPageContentUseCase;
    1212
    1313class GetPageContentRequestHandler implements RequestHandler {
    14     private GetPageContentsByIdUseCase $get_page_contents_by_id_use_case;
     14    private PullLocalPageContentUseCase $pull_local_page_content_use_case;
    1515
    16     public function __construct(
    17         GetPageContentsByIdUseCase $get_page_contents_by_id_use_case
    18     ) {
    19         $this->get_page_contents_by_id_use_case = $get_page_contents_by_id_use_case;
    20     }
     16    public function __construct(
     17        PullLocalPageContentUseCase $pull_local_page_content_use_case
     18    ) {
     19        $this->pull_local_page_content_use_case = $pull_local_page_content_use_case;
     20    }
    2121
    22     public function can_handle_request( PluginRequest $request ): bool {
    23         return $request->get_action() == Endpoints::$GET_PAGE_CONTENT_HOOK;
    24     }
     22    public function can_handle_request( PluginRequest $request ): bool {
     23        return $request->get_action() == Endpoints::$GET_PAGE_CONTENT_HOOK;
     24    }
    2525
    26     public function handle_request( PluginRequest $request ): PluginResponse {
    27         Logger::debug( "Found handler for Appful request" );
     26    public function handle_request( PluginRequest $request ): PluginResponse {
     27        Logger::debug( "Found handler for Appful request" );
    2828
    29         if ( ! isset( $_GET['id'] ) ) {
    30             return PluginResponse::plugin_response()->status( 400 );
    31         }
     29        if ( !isset( $_GET['id'] ) ) {
     30            return PluginResponse::plugin_response()->status( 400 );
     31        }
    3232
    33         $cleaned_id = absint( sanitize_text_field( $_GET['id'] ) );
     33        $cleaned_id = absint( sanitize_text_field( $_GET['id'] ) );
    3434
    35         $request_user_id = $_GET['user_id'] ?? null;
    36         $cleaned_user_id = null;
    37         if ( $request_user_id ) {
    38             $cleaned_user_id = absint( sanitize_text_field( $request_user_id ) );
    39         }
     35        $request_user_id = $_GET['user_id'] ?? null;
     36        $cleaned_user_id = null;
     37        if ( $request_user_id ) {
     38            $cleaned_user_id = absint( sanitize_text_field( $request_user_id ) );
     39        }
    4040
    41         Logger::debug( "Sending page content for id " . json_encode( $cleaned_id ) . " for user " . $request_user_id );
     41        Logger::debug( "Sending page content for id " . json_encode( $cleaned_id ) . " for user " . $request_user_id );
    4242
    43         $page_contents = $this->get_page_contents_by_id_use_case->invoke( [ $cleaned_id ], $cleaned_user_id );
    44         if ( count( $page_contents ) == 1 ) {
    45             return PluginResponse::plugin_response()->body( PageContentMapper::to_dto( $page_contents[0] ) );
    46         } else {
    47             return PluginResponse::plugin_response()->status( 404 );
    48         }
    49     }
     43        $page_content = $this->pull_local_page_content_use_case->invoke( $cleaned_id, $cleaned_user_id );
     44        if ( $page_content != null ) {
     45            return PluginResponse::plugin_response()->body( PageContentMapper::to_dto( $page_content ) );
     46        } else {
     47            return PluginResponse::plugin_response()->status( 404 );
     48        }
     49    }
    5050}
  • appful-app/trunk/includes/use_cases/PullLocalPostContentUseCase.php

    r3018629 r3069513  
    1010
    1111class PullLocalPostContentUseCase {
    12     private SelfClient $self_client;
     12    private SelfClient $self_client;
    1313
    14     public function __construct( SelfClient $self_client ) {
    15         $this->self_client = $self_client;
    16     }
     14    public function __construct( SelfClient $self_client ) {
     15        $this->self_client = $self_client;
     16    }
    1717
    18     public function invoke( int $id ): ?PostContent {
    19         Logger::debug( "Pulling local post content for id: " . $id );
     18    public function invoke( int $id ): ?PostContent {
     19        Logger::debug( "Pulling local post content for id: " . $id );
    2020
    21         $request_params = [];
     21        $request_params = [];
    2222
    23         $request_params['id'] = $id;
    24         if ( isset( $_REQUEST['debug'] ) && $_REQUEST['debug'] == "1" ) {
    25             $request_params['debug'] = "1";
    26         }
     23        $request_params['id'] = $id;
     24        if ( isset( $_REQUEST['debug'] ) && $_REQUEST['debug'] == "1" ) {
     25            $request_params['debug'] = "1";
     26        }
    2727
    28         $request = HttpRequest::backend_request()->method( "GET" )->path( "/" . Endpoints::$GET_POST_CONTENT_LOCAL )->params( $request_params );
    29         $response = $this->self_client->send_request( $request );
     28        $request = HttpRequest::backend_request()->method( "GET" )->path( "/" . Endpoints::$GET_POST_CONTENT_LOCAL )->params( $request_params );
     29        $response = $this->self_client->send_request( $request );
    3030
    31         if ( $response->get_status() != 200 ) {
    32             return null;
    33         }
     31        if ( $response->get_status() != 200 ) {
     32            return null;
     33        }
    3434
    35         $post_content_dto = $response->get_body();
     35        $post_content_dto = $response->get_body();
    3636
    37         return PostContent::postContent()
    38                           ->id( absint( $post_content_dto["id"] ) )
    39                           ->content( $post_content_dto["content"] )
    40                           ->head( $post_content_dto["head"] )
    41                           ->footer( $post_content_dto["footer"] )
    42                           ->body_class( $post_content_dto["body_class"] );
    43     }
     37        if ( $post_content_dto == null ) {
     38            return null;
     39        }
     40
     41        return PostContent::postContent()
     42            ->id( absint( $post_content_dto["id"] ) )
     43            ->content( $post_content_dto["content"] )
     44            ->head( $post_content_dto["head"] )
     45            ->footer( $post_content_dto["footer"] )
     46            ->body_class( $post_content_dto["body_class"] );
     47    }
    4448}
  • appful-app/trunk/includes/use_cases/page/GetPageContentsByIdUseCase.php

    r2978062 r3069513  
    44
    55use AppfulPlugin\Domain\PageContent;
    6 use AppfulPlugin\Wp\WPPageManager;
    76
    87class GetPageContentsByIdUseCase {
    9     private PullLocalPageContentUseCase $pull_local_page_content_use_case;
     8    private PullLocalPageContentUseCase $pull_local_page_content_use_case;
    109
    11     public function __construct( PullLocalPageContentUseCase $pull_local_page_content_use_case ) {
    12         $this->pull_local_page_content_use_case = $pull_local_page_content_use_case;
    13     }
     10    public function __construct( PullLocalPageContentUseCase $pull_local_page_content_use_case ) {
     11        $this->pull_local_page_content_use_case = $pull_local_page_content_use_case;
     12    }
    1413
    15     /**
    16     * @param int[] $ids
    17     *
    18     * @return PageContent[]
    19     */
    20     public function invoke( array $ids, ?int $user_id = null ): array {
    21         $page_contents = [];
     14    /**
     15    * @param int[] $ids
     16    *
     17    * @return PageContent[]
     18    */
     19    public function invoke( array $ids, ?int $user_id = null ): array {
     20        $page_contents = [];
    2221
    23         $page_contents = WPPageManager::get_page_contents_by_ids($ids, $user_id);
    24 //      Uncomment if for some reason fetching all pages at once should not work
    25 //      foreach ( $ids as $page_id ) {
    26 //          $response = $this->pull_local_page_content_use_case->invoke( $page_id, $user_id );
    27 //          if ( $response != null ) {
    28 //              $page_contents[] = $response;
    29 //          }
    30 //      }
     22        foreach ($ids as $page_id) {
     23            $response = $this->pull_local_page_content_use_case->invoke( $page_id, $user_id );
     24            if ( $response != null ) {
     25                $page_contents[] = $response;
     26            }
     27        }
    3128
    32         return $page_contents;
    33     }
     29        return $page_contents;
     30    }
    3431}
  • appful-app/trunk/includes/use_cases/page/PullLocalPageContentUseCase.php

    r3018629 r3069513  
    1010
    1111class PullLocalPageContentUseCase {
    12     private SelfClient $self_client;
     12    private SelfClient $self_client;
    1313
    14     public function __construct( SelfClient $self_client ) {
    15         $this->self_client = $self_client;
    16     }
     14    public function __construct( SelfClient $self_client ) {
     15        $this->self_client = $self_client;
     16    }
    1717
    18     public function invoke( int $id, ?int $user_id = null ): ?PageContent {
    19         Logger::debug( "Pulling local page content for id " . $id . " for user " . $user_id );
     18    public function invoke( int $id, ?int $user_id = null ): ?PageContent {
     19        Logger::debug( "Pulling local page content for id " . $id . " for user " . $user_id );
    2020
    21         $request_params = [];
     21        $request_params = [];
    2222
    23         $request_params['id'] = $id;
    24         if ( isset( $_REQUEST['debug'] ) && $_REQUEST['debug'] == "1" ) {
    25             $request_params['debug'] = "1";
    26         }
    27         if ( $user_id ) {
    28             $request_params['user_id'] = $user_id;
    29         }
     23        $request_params['id'] = $id;
     24        if ( isset( $_REQUEST['debug'] ) && $_REQUEST['debug'] == "1" ) {
     25            $request_params['debug'] = "1";
     26        }
     27        if ( $user_id ) {
     28            $request_params['user_id'] = $user_id;
     29        }
    3030
    31         $request = HttpRequest::backend_request()->method( "GET" )->path( "/" . Endpoints::$GET_PAGE_CONTENT_LOCAL )->params( $request_params );
    32         $response = $this->self_client->send_request( $request );
     31        $request = HttpRequest::backend_request()->method( "GET" )->path( "/" . Endpoints::$GET_PAGE_CONTENT_LOCAL )->params( $request_params );
     32        $response = $this->self_client->send_request( $request );
    3333
    34         if ( $response->get_status() != 200 ) {
    35             return null;
    36         }
     34        if ( $response->get_status() != 200 ) {
     35            return null;
     36        }
    3737
    38         $page_content_dto = $response->get_body();
     38        $page_content_dto = $response->get_body();
    3939
    40         return PageContent::pageContent()
    41                           ->id( absint( $page_content_dto["id"] ) )
    42                           ->content( $page_content_dto["content"] )
    43                           ->head( $page_content_dto["head"] )
    44                           ->footer( $page_content_dto["footer"] )
    45                           ->body_class( $page_content_dto["body_class"] );
    46     }
     40        if ( $page_content_dto == null ) {
     41            return null;
     42        }
     43
     44        return PageContent::pageContent()
     45            ->id( absint( $page_content_dto["id"] ) )
     46            ->content( $page_content_dto["content"] )
     47            ->head( $page_content_dto["head"] )
     48            ->footer( $page_content_dto["footer"] )
     49            ->body_class( $page_content_dto["body_class"] );
     50    }
    4751}
  • appful-app/trunk/includes/wp/WPAttachmentManager.php

    r3019874 r3069513  
    9696        ];
    9797
    98         $all_attachments = get_posts( $args );
     98        $all_attachments = LanguageHelper::for_each_language( function () use ( $args ) {
     99            return get_posts( $args );
     100        } );
    99101
    100102        $all_attachments = array_values(
  • appful-app/trunk/includes/wp/WPCommentDatabaseManager.php

    r3019874 r3069513  
    2525        global $wpdb;
    2626
    27         $query = $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments AS comment" );
    28 
    29         return $wpdb->get_var( $query );
     27        return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments" );
    3028    }
    3129}
  • appful-app/trunk/includes/wp/WPCommentManager.php

    r3019874 r3069513  
    1212
    1313class WPCommentManager {
    14     public static function get_comment_count(): int {
    15         return WPCommentDatabaseManager::get_count();
    16     }
     14    public static function get_comment_count(): int {
     15        return WPCommentDatabaseManager::get_count();
     16    }
    1717
    18     /** @return SyncItem[] */
    19     public static function get_comment_sync_items( int $offset, int $count ): array {
    20         return WPCommentDatabaseManager::get_sync_items( $count, $offset );
    21     }
     18    /** @return SyncItem[] */
     19    public static function get_comment_sync_items( int $offset, int $count ): array {
     20        return WPCommentDatabaseManager::get_sync_items( $count, $offset );
     21    }
    2222
    23     /**
    24     * @param int[] $ids
    25     *
    26     * @return Comment[]
    27     */
    28     public static function get_comments_by_id( array $ids ): array {
    29         $args = [
    30             "status"      => array_keys( get_comment_statuses() ),
    31             "comment__in" => $ids
    32         ];
     23    /**
     24    * @param int[] $ids
     25    *
     26    * @return Comment[]
     27    */
     28    public static function get_comments_by_id( array $ids ): array {
     29        $args = [
     30            "status" => array_keys( get_comment_statuses() ),
     31            "comment__in" => $ids
     32        ];
    3333
    34         $all_comments = LanguageHelper::for_each_language( function () use ( $args ) {
    35             return get_comments( $args );
    36         } );
     34        $all_comments = LanguageHelper::for_each_language( function () use ( $args ) {
     35            return get_comments( $args );
     36        } );
    3737
    38         return array_map(
    39             function ( WP_Comment $comment ) {
    40                 return CommentMapper::to_domain( $comment );
    41             },
    42             $all_comments
    43         );
    44     }
     38        return array_map(
     39            function ( WP_Comment $comment ) {
     40                return CommentMapper::to_domain( $comment );
     41            },
     42            $all_comments
     43        );
     44    }
    4545
    46     public static function create_comment( CreateCommentRequest $request ): ?Comment {
    47         $commentData = [
    48             'comment_author'      => $request->get_username(), // The name of the author of the comment.
    49             'comment_author_email' => $request->get_email(), // The email address of the $comment_author.
    50             'comment_content'      => $request->get_content(), // The content of the comment.
    51             'comment_post_ID'      => $request->get_post_id(), // ID of the post that relates to the comment.
    52             'comment_parent'      => $request->get_parent_id(), // ID of this comment's parent, if any.
    53         ];
     46    public static function create_comment( CreateCommentRequest $request ): ?Comment {
     47        $commentData = [
     48            'comment_author' => $request->get_username(), // The name of the author of the comment.
     49            'comment_author_email' => $request->get_email(), // The email address of the $comment_author.
     50            'comment_content' => $request->get_content(), // The content of the comment.
     51            'comment_post_ID' => $request->get_post_id(), // ID of the post that relates to the comment.
     52            'comment_parent' => $request->get_parent_id(), // ID of this comment's parent, if any.
     53        ];
    5454
    55         $commentId = wp_insert_comment( $commentData );
     55        $commentId = wp_insert_comment( $commentData );
    5656
    57         if ( $commentId === false ) {
    58             Logger::error( "Insert comment failed" );
     57        if ( $commentId === false ) {
     58            Logger::error( "Insert comment failed" );
    5959
    60             return null;
    61         }
     60            return null;
     61        }
    6262
    63         $comment = get_comment( $commentId );
     63        $comment = get_comment( $commentId );
    6464
    65         if ( ! $comment instanceof WP_Comment ) {
    66             Logger::error( "Getting comment failed!" );
     65        if ( !$comment instanceof WP_Comment ) {
     66            Logger::error( "Getting comment failed!" );
    6767
    68             return null;
    69         }
     68            return null;
     69        }
    7070
    71         return CommentMapper::to_domain( $comment );
    72     }
     71        return CommentMapper::to_domain( $comment );
     72    }
    7373}
  • appful-app/trunk/includes/wp/WPPageManager.php

    r3019874 r3069513  
    1111
    1212class WPPageManager {
    13     public static function get_page_permalink( WP_Post $page ): ?string {
    14         return get_permalink( $page );
    15     }
     13    public static function get_page_permalink( WP_Post $page ): ?string {
     14        return get_permalink( $page );
     15    }
    1616
    17     public static function get_page_language( int $page_id ): string {
    18         return LanguageHelper::get_page_language( $page_id );
    19     }
     17    public static function get_page_language( int $page_id ): string {
     18        return LanguageHelper::get_page_language( $page_id );
     19    }
    2020
    21     public static function get_page_count(): int {
    22         return WPPostDatabaseManager::get_count_for_type( "page" );
    23     }
     21    public static function get_page_count(): int {
     22        return WPPostDatabaseManager::get_count_for_type( "page" );
     23    }
    2424
    25     /** @return SyncItem[] */
    26     public static function get_page_sync_items( int $offset, int $count ): array {
    27         return WPPostDatabaseManager::get_sync_items_for_type( "page", $count, $offset );
    28     }
     25    /** @return SyncItem[] */
     26    public static function get_page_sync_items( int $offset, int $count ): array {
     27        return WPPostDatabaseManager::get_sync_items_for_type( "page", $count, $offset );
     28    }
    2929
    30     /**
    31      * @param int[] $ids
    32      *
    33      * @return Page[]
    34      */
    35     public static function get_pages_by_id( array $ids ): array {
    36         $args = [
    37             "numberposts" => - 1,
    38             "post_status" => self::get_allowed_page_stati()
    39         ];
     30    /**
     31     * @param int[] $ids
     32     *
     33     * @return Page[]
     34     */
     35    public static function get_pages_by_id( array $ids ): array {
     36        $args = [
     37            "numberposts" => -1,
     38            "include" => $ids,
     39            "post_status" => self::get_allowed_page_stati()
     40        ];
    4041
    41         $all_pages = get_pages( $args );
     42        $all_pages = LanguageHelper::for_each_language( function () use ( $args ) {
     43            return get_pages( $args );
     44        } );
    4245
    43         $all_pages = array_values(
    44             array_filter( $all_pages, function ( WP_Post $page ) use ( $ids ) {
    45                 return in_array( $page->ID, $ids );
    46             } )
    47         );
     46        $all_pages = array_values(
     47            array_filter( $all_pages, function ( WP_Post $page ) use ( $ids ) {
     48                return in_array( $page->ID, $ids );
     49            } )
     50        );
    4851
    49         return array_map(
    50             function ( WP_Post $page ) {
    51                 return PageMapper::to_domain( $page );
    52             },
    53             $all_pages
    54         );
    55     }
     52        return array_map(
     53            function ( WP_Post $page ) {
     54                return PageMapper::to_domain( $page );
     55            },
     56            $all_pages
     57        );
     58    }
    5659
    57     public static function get_page_content_by_id( int $id, ?int $user_id = null ): ?PageContent {
    58         global $wp_query;
     60    public static function get_page_content_by_id( int $id, ?int $user_id = null ): ?PageContent {
     61        if ( $user_id ) {
     62            wp_set_current_user( $user_id );
     63        }
    5964
    60         if ( $user_id ) {
    61             wp_set_current_user( $user_id );
    62         }
     65        $args = [
     66            "posts_per_page" => 1,
     67            "post_type" => "page",
     68            "p" => $id,
     69            "post_status" => self::get_allowed_page_stati()
     70        ];
    6371
    64         $args = [
    65             "posts_per_page" => 1,
    66             "post_type"      => "page",
    67             "p"              => $id,
    68             "post_status"    => self::get_allowed_page_stati()
    69         ];
     72        $page_language = self::get_page_language( $id );
     73        return LanguageHelper::for_language(
     74            $page_language,
     75            function () use ( $args ) {
     76                global $wp_query;
    7077
    71         $wp_query = new \WP_Query( $args );
     78                do_action( 'template_redirect' );
    7279
    73         do_action( 'template_redirect' );
     80                $wp_query = new \WP_Query( $args );
    7481
    75         if ( have_posts() ) {
    76             the_post();
     82                if ( have_posts() ) {
     83                    the_post();
    7784
    78             ob_start();
    79             wp_head();
    80             $head = ob_get_clean();
     85                    ob_start();
     86                    wp_head();
     87                    $head = ob_get_clean();
    8188
    82             ob_start();
    83             the_content();
    84             $content = ob_get_clean();
     89                    ob_start();
     90                    the_content();
     91                    $content = ob_get_clean();
    8592
    86             ob_start();
    87             wp_footer();
    88             $footer = ob_get_clean();
     93                    ob_start();
     94                    wp_footer();
     95                    $footer = ob_get_clean();
    8996
    90             ob_start();
    91             body_class();
    92             $body_class = ob_get_clean();
     97                    ob_start();
     98                    body_class();
     99                    $body_class = ob_get_clean();
    93100
    94             wp_reset_postdata();
     101                    wp_reset_postdata();
    95102
    96             return PageContent::pageContent()
    97                               ->id( get_the_ID() )
    98                               ->content( $content )
    99                               ->head( $head )
    100                               ->footer( $footer )
    101                               ->body_class( $body_class );
    102         }
     103                    return PageContent::pageContent()
     104                        ->id( get_the_ID() )
     105                        ->content( $content )
     106                        ->head( $head )
     107                        ->footer( $footer )
     108                        ->body_class( $body_class );
     109                }
    103110
    104         return null;
    105     }
     111                return null;
     112            }
     113        );
     114    }
    106115
    107     public static function get_page_contents_by_ids( array $ids, ?int $user_id = null ): array {
    108         global $wp_query;
    109 
    110         if ( $user_id ) {
    111             wp_set_current_user( $user_id );
    112         }
    113 
    114         $args = [
    115             "posts_per_page" => - 1,
    116             "post_type"      => "page",
    117             "post__in"       => $ids,
    118             "post_status"    => self::get_allowed_page_stati()
    119         ];
    120 
    121         $wp_query = new \WP_Query( $args );
    122 
    123         do_action( 'template_redirect' );
    124 
    125         $pages = [];
    126 
    127         if ( have_posts() ) {
    128             ob_start();
    129             wp_head();
    130             $head = ob_get_clean();
    131 
    132             ob_start();
    133             body_class();
    134             $body_class = ob_get_clean();
    135 
    136             while ( have_posts() ) {
    137                 the_post();
    138 
    139                 ob_start();
    140                 the_content();
    141                 $content = ob_get_clean();
    142 
    143                 $pages[] = PageContent::pageContent()
    144                                       ->id( get_the_ID() )
    145                                       ->content( $content )
    146                                       ->head( $head )
    147                                       ->footer( "" )
    148                                       ->body_class( $body_class );
    149             }
    150 
    151             ob_start();
    152             wp_footer();
    153             $footer = ob_get_clean();
    154 
    155             $pages = array_map( function ( PageContent $content ) use ( $footer ) {
    156                 return $content->footer( $footer );
    157             }, $pages );
    158         }
    159 
    160         wp_reset_postdata();
    161 
    162         return $pages;
    163     }
    164 
    165     /**
    166      * @return string[]
    167      */
    168     private static function get_allowed_page_stati(): array {
    169         return array_filter( get_post_stati(), function ( string $status ) {
    170             return $status != "auto-draft";
    171         } );
    172     }
     116    /**
     117     * @return string[]
     118     */
     119    private static function get_allowed_page_stati(): array {
     120        return array_filter( get_post_stati(), function ( string $status ) {
     121            return $status != "auto-draft";
     122        } );
     123    }
    173124}
  • appful-app/trunk/includes/wp/WPPostManager.php

    r3043568 r3069513  
    131131
    132132    public static function get_post_content_by_id( int $id ): ?PostContent {
    133         global $wp_query;
    134 
    135133        $args = [
    136134            "post_type"   => "post",
     
    139137        ];
    140138
    141         $wp_query = new \WP_Query( $args );
    142 
    143         self::setup_wp_call();
    144 
    145         if ( have_posts() ) {
    146             the_post();
    147 
    148             Logger::debug( "Getting head!" );
    149             $head = self::get_data_code( 'wp_head' );
    150             Logger::debug( "Getting content!" );
    151             $content = self::get_data_code( 'the_content' );
    152             Logger::debug( "Getting footer!" );
    153             $footer = self::get_data_code( 'wp_footer' );
    154             Logger::debug( "Getting body classes!" );
    155             $body_class = self::get_data_code( 'body_class' );
    156 
    157             wp_reset_postdata();
    158 
    159             return PostContent::postContent()
    160                               ->id( get_the_ID() )
    161                               ->content( $content )
    162                               ->head( $head )
    163                               ->footer( $footer )
    164                               ->body_class( $body_class );
    165         }
    166 
    167         return null;
     139        $post_language = self::get_post_language( $id );
     140        return LanguageHelper::for_language(
     141            $post_language,
     142            function() use ( $args ) {
     143                global $wp_query;
     144
     145                $wp_query = new \WP_Query( $args );
     146
     147                self::setup_wp_call();
     148
     149                if ( have_posts() ) {
     150                    the_post();
     151
     152                    Logger::debug( "Getting head!" );
     153                    $head = self::get_data_code( 'wp_head' );
     154                    Logger::debug( "Getting content!" );
     155                    $content = self::get_data_code( 'the_content' );
     156                    Logger::debug( "Getting footer!" );
     157                    $footer = self::get_data_code( 'wp_footer' );
     158                    Logger::debug( "Getting body classes!" );
     159                    $body_class = self::get_data_code( 'body_class' );
     160
     161                    wp_reset_postdata();
     162
     163                    return PostContent::postContent()
     164                        ->id( get_the_ID() )
     165                        ->content( $content )
     166                        ->head( $head )
     167                        ->footer( $footer )
     168                        ->body_class( $body_class );
     169                }
     170
     171                return null;
     172            }
     173        );
    168174    }
    169175
  • appful-app/trunk/includes/wp/WPUserDatabaseManager.php

    r3019874 r3069513  
    2525        global $wpdb;
    2626
    27         $query = $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->users AS user" );
    28 
    29         return $wpdb->get_var( $query );
     27        return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
    3028    }
    3129}
  • appful-app/trunk/lib/vendor/composer/installed.php

    r3043568 r3069513  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '6f0d2c0f0f21f2ca2550d7a07d32827d416dc20c',
     6        'reference' => '455447cb78389ae33d8dd91f6fcc71f5b36b9f5a',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '6f0d2c0f0f21f2ca2550d7a07d32827d416dc20c',
     16            'reference' => '455447cb78389ae33d8dd91f6fcc71f5b36b9f5a',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
  • appful-app/trunk/readme.txt

    r3053321 r3069513  
    66Tested up to: 6.4
    77Requires PHP: 7.4
    8 Stable tag: 3.1.24
     8Stable tag: 3.1.25
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.