Plugin Directory

Changeset 2954441


Ignore:
Timestamp:
08/16/2023 01:32:28 PM (3 years ago)
Author:
appfulapp
Message:

Fixed comment creation endpoint

Location:
appful-app
Files:
6 added
3 deleted
10 edited
75 copied

Legend:

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

    r2936340 r2954441  
    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.7
     14 * Version:           3.1.8
    1515 * Requires at least: 5.8
    1616 * Requires PHP:      7.4
  • appful-app/tags/3.1.8/includes/api/Api.php

    r2920030 r2954441  
    4444        $token = null;
    4545
    46         if ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) && 0 === stripos( $_SERVER['HTTP_AUTHORIZATION'], "Bearer " ) ) {
    47             $token = sanitize_text_field( substr( $_SERVER['HTTP_AUTHORIZATION'], strlen( "Bearer " ) ) );
     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 " ) ) );
    4849        }
     50
    4951        if ( $token == null ) {
    5052            $this->unauthorized();
  • appful-app/tags/3.1.8/includes/api/ReqHandler.php

    r2920603 r2954441  
    1010use AppfulPlugin\Api\Handlers\ClearLogRequestHandler;
    1111use AppfulPlugin\Api\Handlers\CommentSyncRequestHandler;
     12use AppfulPlugin\Api\Handlers\CreateCommentRequestHandler;
    1213use AppfulPlugin\Api\Handlers\GetAttachmentsRequestHandler;
    1314use AppfulPlugin\Api\Handlers\GetCategoriesRequestHandler;
     
    5657            new AuthenticateUserRequestHandler( $use_case_manager->get_authenticate_user_use_case() ),
    5758            new PullLocalPostContentRequestHandler( $use_case_manager->get_get_local_post_content_by_id_use_case() ),
     59            new CreateCommentRequestHandler( $use_case_manager->create_comment_use_case() ),
    5860        ];
    5961    }
  • appful-app/tags/3.1.8/includes/use_cases/UseCaseManager.php

    r2920184 r2954441  
    5757    private PullLocalPostContentUseCase $pull_local_post_content_use_case;
    5858    private GetLocalPostContentByIdUseCase $get_local_post_content_by_id_use_case;
     59    private CreateCommentUseCase $create_comment_use_case;
    5960
    6061    public function __construct( BackendClient $backend_client, SelfClient $self_client ) {
     
    109110        $this->get_local_post_content_by_id_use_case   = new GetLocalPostContentByIdUseCase();
    110111        $this->get_post_contents_by_id_use_case        = new GetPostContentsByIdUseCase( $this->pull_local_post_content_use_case );
     112        $this->create_comment_use_case                 = new CreateCommentUseCase();
    111113    }
    112114
     
    310312        return $this->get_local_post_content_by_id_use_case;
    311313    }
     314
     315    public function create_comment_use_case(): CreateCommentUseCase {
     316        return $this->create_comment_use_case;
     317    }
    312318}
  • appful-app/tags/3.1.8/includes/wp/WPCommentManager.php

    r2907312 r2954441  
    44
    55use AppfulPlugin\Domain\Comment;
     6use AppfulPlugin\Domain\CreateCommentRequest;
     7use AppfulPlugin\Helper\Logger;
    68use AppfulPlugin\Wp\Mapper\CommentMapper;
    79use AppfulPlugin\Wp\Plugins\LanguageHelper;
     
    4951        );
    5052    }
     53
     54    public static function create_comment( CreateCommentRequest $request ): ?Comment {
     55        $commentData = [
     56            'comment_author'       => $request->get_username(), // The name of the author of the comment.
     57            'comment_author_email' => $request->get_email(), // The email address of the $comment_author.
     58            'comment_content'      => $request->get_content(), // The content of the comment.
     59            'comment_post_ID'      => $request->get_post_id(), // ID of the post that relates to the comment.
     60            'comment_parent'       => $request->get_parent_id(), // ID of this comment's parent, if any.
     61        ];
     62
     63        $commentId = wp_insert_comment($commentData);
     64
     65        if ($commentId === false) {
     66            Logger::log( "Insert comment failed" );
     67            return null;
     68        }
     69        Logger::log( "Inserted comment!" );
     70
     71        $comment = get_comment($commentId);
     72
     73        if (!$comment instanceof WP_Comment) {
     74            Logger::log( "Getting comment failed!" );
     75            return null;
     76        }
     77
     78        return CommentMapper::to_domain($comment);
     79    }
    5180}
  • appful-app/tags/3.1.8/lib/vendor/composer/autoload_classmap.php

    r2920184 r2954441  
    3030    'AppfulPlugin\\Api\\Handlers\\ClearLogRequestHandler' => $baseDir . '/../includes/api/handlers/ClearLogRequestHandler.php',
    3131    'AppfulPlugin\\Api\\Handlers\\CommentSyncRequestHandler' => $baseDir . '/../includes/api/handlers/CommentSyncRequestHandler.php',
     32    'AppfulPlugin\\Api\\Handlers\\CreateCommentRequestHandler' => $baseDir . '/../includes/api/handlers/CreateCommentRequestHandler.php',
    3233    'AppfulPlugin\\Api\\Handlers\\GetAttachmentsRequestHandler' => $baseDir . '/../includes/api/handlers/GetAttachmentsRequestHandler.php',
    3334    'AppfulPlugin\\Api\\Handlers\\GetCategoriesRequestHandler' => $baseDir . '/../includes/api/handlers/GetCategoriesRequestHandler.php',
     
    7071    'AppfulPlugin\\Domain\\Category' => $baseDir . '/../includes/domain/Category.php',
    7172    'AppfulPlugin\\Domain\\Comment' => $baseDir . '/../includes/domain/Comment.php',
     73    'AppfulPlugin\\Domain\\CreateCommentRequest' => $baseDir . '/../includes/domain/CreateCommentRequest.php',
    7274    'AppfulPlugin\\Domain\\Post' => $baseDir . '/../includes/domain/Post.php',
    7375    'AppfulPlugin\\Domain\\PostContent' => $baseDir . '/../includes/domain/PostContent.php',
     
    103105    'AppfulPlugin\\UseCases\\CommentDeleteUseCase' => $baseDir . '/../includes/use_cases/CommentDeleteUseCase.php',
    104106    'AppfulPlugin\\UseCases\\CommentSaveUseCase' => $baseDir . '/../includes/use_cases/CommentSaveUseCase.php',
     107    'AppfulPlugin\\UseCases\\CreateCommentUseCase' => $baseDir . '/../includes/use_cases/CreateCommentUseCase.php',
    105108    'AppfulPlugin\\UseCases\\DeleteSessionUseCase' => $baseDir . '/../includes/use_cases/DeleteSessionUseCase.php',
    106109    'AppfulPlugin\\UseCases\\GetAndroidAssetLinkUseCase' => $baseDir . '/../includes/use_cases/GetAndroidAssetLinkUseCase.php',
  • appful-app/tags/3.1.8/lib/vendor/composer/autoload_static.php

    r2920184 r2954441  
    197197        'AppfulPlugin\\Api\\Handlers\\ClearLogRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/ClearLogRequestHandler.php',
    198198        'AppfulPlugin\\Api\\Handlers\\CommentSyncRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/CommentSyncRequestHandler.php',
     199        'AppfulPlugin\\Api\\Handlers\\CreateCommentRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/CreateCommentRequestHandler.php',
    199200        'AppfulPlugin\\Api\\Handlers\\GetAttachmentsRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/GetAttachmentsRequestHandler.php',
    200201        'AppfulPlugin\\Api\\Handlers\\GetCategoriesRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/GetCategoriesRequestHandler.php',
     
    237238        'AppfulPlugin\\Domain\\Category' => __DIR__ . '/../..' . '/../includes/domain/Category.php',
    238239        'AppfulPlugin\\Domain\\Comment' => __DIR__ . '/../..' . '/../includes/domain/Comment.php',
     240        'AppfulPlugin\\Domain\\CreateCommentRequest' => __DIR__ . '/../..' . '/../includes/domain/CreateCommentRequest.php',
    239241        'AppfulPlugin\\Domain\\Post' => __DIR__ . '/../..' . '/../includes/domain/Post.php',
    240242        'AppfulPlugin\\Domain\\PostContent' => __DIR__ . '/../..' . '/../includes/domain/PostContent.php',
     
    270272        'AppfulPlugin\\UseCases\\CommentDeleteUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/CommentDeleteUseCase.php',
    271273        'AppfulPlugin\\UseCases\\CommentSaveUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/CommentSaveUseCase.php',
     274        'AppfulPlugin\\UseCases\\CreateCommentUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/CreateCommentUseCase.php',
    272275        'AppfulPlugin\\UseCases\\DeleteSessionUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/DeleteSessionUseCase.php',
    273276        'AppfulPlugin\\UseCases\\GetAndroidAssetLinkUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/GetAndroidAssetLinkUseCase.php',
  • appful-app/tags/3.1.8/lib/vendor/composer/installed.php

    r2936340 r2954441  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '2142f2e59a034cea9d7682d4dd48a5fdedf39de7',
     6        'reference' => '4d8e7b6e341ee0d4e0bee5c8146a5f473c37c66b',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '2142f2e59a034cea9d7682d4dd48a5fdedf39de7',
     16            'reference' => '4d8e7b6e341ee0d4e0bee5c8146a5f473c37c66b',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
  • appful-app/tags/3.1.8/readme.txt

    r2936340 r2954441  
    66Tested up to: 6.2
    77Requires PHP: 7.4
    8 Stable tag: 3.1.7
     8Stable tag: 3.1.8
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • appful-app/trunk/appful-app.php

    r2936340 r2954441  
    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.7
     14 * Version:           3.1.8
    1515 * Requires at least: 5.8
    1616 * Requires PHP:      7.4
  • appful-app/trunk/includes/api/Api.php

    r2920030 r2954441  
    4444        $token = null;
    4545
    46         if ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) && 0 === stripos( $_SERVER['HTTP_AUTHORIZATION'], "Bearer " ) ) {
    47             $token = sanitize_text_field( substr( $_SERVER['HTTP_AUTHORIZATION'], strlen( "Bearer " ) ) );
     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 " ) ) );
    4849        }
     50
    4951        if ( $token == null ) {
    5052            $this->unauthorized();
  • appful-app/trunk/includes/api/ReqHandler.php

    r2920603 r2954441  
    1010use AppfulPlugin\Api\Handlers\ClearLogRequestHandler;
    1111use AppfulPlugin\Api\Handlers\CommentSyncRequestHandler;
     12use AppfulPlugin\Api\Handlers\CreateCommentRequestHandler;
    1213use AppfulPlugin\Api\Handlers\GetAttachmentsRequestHandler;
    1314use AppfulPlugin\Api\Handlers\GetCategoriesRequestHandler;
     
    5657            new AuthenticateUserRequestHandler( $use_case_manager->get_authenticate_user_use_case() ),
    5758            new PullLocalPostContentRequestHandler( $use_case_manager->get_get_local_post_content_by_id_use_case() ),
     59            new CreateCommentRequestHandler( $use_case_manager->create_comment_use_case() ),
    5860        ];
    5961    }
  • appful-app/trunk/includes/use_cases/UseCaseManager.php

    r2920184 r2954441  
    5757    private PullLocalPostContentUseCase $pull_local_post_content_use_case;
    5858    private GetLocalPostContentByIdUseCase $get_local_post_content_by_id_use_case;
     59    private CreateCommentUseCase $create_comment_use_case;
    5960
    6061    public function __construct( BackendClient $backend_client, SelfClient $self_client ) {
     
    109110        $this->get_local_post_content_by_id_use_case   = new GetLocalPostContentByIdUseCase();
    110111        $this->get_post_contents_by_id_use_case        = new GetPostContentsByIdUseCase( $this->pull_local_post_content_use_case );
     112        $this->create_comment_use_case                 = new CreateCommentUseCase();
    111113    }
    112114
     
    310312        return $this->get_local_post_content_by_id_use_case;
    311313    }
     314
     315    public function create_comment_use_case(): CreateCommentUseCase {
     316        return $this->create_comment_use_case;
     317    }
    312318}
  • appful-app/trunk/includes/wp/WPCommentManager.php

    r2907312 r2954441  
    44
    55use AppfulPlugin\Domain\Comment;
     6use AppfulPlugin\Domain\CreateCommentRequest;
     7use AppfulPlugin\Helper\Logger;
    68use AppfulPlugin\Wp\Mapper\CommentMapper;
    79use AppfulPlugin\Wp\Plugins\LanguageHelper;
     
    4951        );
    5052    }
     53
     54    public static function create_comment( CreateCommentRequest $request ): ?Comment {
     55        $commentData = [
     56            'comment_author'       => $request->get_username(), // The name of the author of the comment.
     57            'comment_author_email' => $request->get_email(), // The email address of the $comment_author.
     58            'comment_content'      => $request->get_content(), // The content of the comment.
     59            'comment_post_ID'      => $request->get_post_id(), // ID of the post that relates to the comment.
     60            'comment_parent'       => $request->get_parent_id(), // ID of this comment's parent, if any.
     61        ];
     62
     63        $commentId = wp_insert_comment($commentData);
     64
     65        if ($commentId === false) {
     66            Logger::log( "Insert comment failed" );
     67            return null;
     68        }
     69        Logger::log( "Inserted comment!" );
     70
     71        $comment = get_comment($commentId);
     72
     73        if (!$comment instanceof WP_Comment) {
     74            Logger::log( "Getting comment failed!" );
     75            return null;
     76        }
     77
     78        return CommentMapper::to_domain($comment);
     79    }
    5180}
  • appful-app/trunk/lib/vendor/composer/autoload_classmap.php

    r2920184 r2954441  
    3030    'AppfulPlugin\\Api\\Handlers\\ClearLogRequestHandler' => $baseDir . '/../includes/api/handlers/ClearLogRequestHandler.php',
    3131    'AppfulPlugin\\Api\\Handlers\\CommentSyncRequestHandler' => $baseDir . '/../includes/api/handlers/CommentSyncRequestHandler.php',
     32    'AppfulPlugin\\Api\\Handlers\\CreateCommentRequestHandler' => $baseDir . '/../includes/api/handlers/CreateCommentRequestHandler.php',
    3233    'AppfulPlugin\\Api\\Handlers\\GetAttachmentsRequestHandler' => $baseDir . '/../includes/api/handlers/GetAttachmentsRequestHandler.php',
    3334    'AppfulPlugin\\Api\\Handlers\\GetCategoriesRequestHandler' => $baseDir . '/../includes/api/handlers/GetCategoriesRequestHandler.php',
     
    7071    'AppfulPlugin\\Domain\\Category' => $baseDir . '/../includes/domain/Category.php',
    7172    'AppfulPlugin\\Domain\\Comment' => $baseDir . '/../includes/domain/Comment.php',
     73    'AppfulPlugin\\Domain\\CreateCommentRequest' => $baseDir . '/../includes/domain/CreateCommentRequest.php',
    7274    'AppfulPlugin\\Domain\\Post' => $baseDir . '/../includes/domain/Post.php',
    7375    'AppfulPlugin\\Domain\\PostContent' => $baseDir . '/../includes/domain/PostContent.php',
     
    103105    'AppfulPlugin\\UseCases\\CommentDeleteUseCase' => $baseDir . '/../includes/use_cases/CommentDeleteUseCase.php',
    104106    'AppfulPlugin\\UseCases\\CommentSaveUseCase' => $baseDir . '/../includes/use_cases/CommentSaveUseCase.php',
     107    'AppfulPlugin\\UseCases\\CreateCommentUseCase' => $baseDir . '/../includes/use_cases/CreateCommentUseCase.php',
    105108    'AppfulPlugin\\UseCases\\DeleteSessionUseCase' => $baseDir . '/../includes/use_cases/DeleteSessionUseCase.php',
    106109    'AppfulPlugin\\UseCases\\GetAndroidAssetLinkUseCase' => $baseDir . '/../includes/use_cases/GetAndroidAssetLinkUseCase.php',
  • appful-app/trunk/lib/vendor/composer/autoload_static.php

    r2920184 r2954441  
    197197        'AppfulPlugin\\Api\\Handlers\\ClearLogRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/ClearLogRequestHandler.php',
    198198        'AppfulPlugin\\Api\\Handlers\\CommentSyncRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/CommentSyncRequestHandler.php',
     199        'AppfulPlugin\\Api\\Handlers\\CreateCommentRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/CreateCommentRequestHandler.php',
    199200        'AppfulPlugin\\Api\\Handlers\\GetAttachmentsRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/GetAttachmentsRequestHandler.php',
    200201        'AppfulPlugin\\Api\\Handlers\\GetCategoriesRequestHandler' => __DIR__ . '/../..' . '/../includes/api/handlers/GetCategoriesRequestHandler.php',
     
    237238        'AppfulPlugin\\Domain\\Category' => __DIR__ . '/../..' . '/../includes/domain/Category.php',
    238239        'AppfulPlugin\\Domain\\Comment' => __DIR__ . '/../..' . '/../includes/domain/Comment.php',
     240        'AppfulPlugin\\Domain\\CreateCommentRequest' => __DIR__ . '/../..' . '/../includes/domain/CreateCommentRequest.php',
    239241        'AppfulPlugin\\Domain\\Post' => __DIR__ . '/../..' . '/../includes/domain/Post.php',
    240242        'AppfulPlugin\\Domain\\PostContent' => __DIR__ . '/../..' . '/../includes/domain/PostContent.php',
     
    270272        'AppfulPlugin\\UseCases\\CommentDeleteUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/CommentDeleteUseCase.php',
    271273        'AppfulPlugin\\UseCases\\CommentSaveUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/CommentSaveUseCase.php',
     274        'AppfulPlugin\\UseCases\\CreateCommentUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/CreateCommentUseCase.php',
    272275        'AppfulPlugin\\UseCases\\DeleteSessionUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/DeleteSessionUseCase.php',
    273276        'AppfulPlugin\\UseCases\\GetAndroidAssetLinkUseCase' => __DIR__ . '/../..' . '/../includes/use_cases/GetAndroidAssetLinkUseCase.php',
  • appful-app/trunk/lib/vendor/composer/installed.php

    r2936340 r2954441  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '2142f2e59a034cea9d7682d4dd48a5fdedf39de7',
     6        'reference' => '4d8e7b6e341ee0d4e0bee5c8146a5f473c37c66b',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '2142f2e59a034cea9d7682d4dd48a5fdedf39de7',
     16            'reference' => '4d8e7b6e341ee0d4e0bee5c8146a5f473c37c66b',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
  • appful-app/trunk/readme.txt

    r2936340 r2954441  
    66Tested up to: 6.2
    77Requires PHP: 7.4
    8 Stable tag: 3.1.7
     8Stable tag: 3.1.8
    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.