CampaignCommentsShortcode.php
11 months ago
CampaignDonationsShortcode.php
11 months ago
CampaignDonorsShortcode.php
11 months ago
CampaignFormShortcode.php
11 months ago
CampaignGoalShortcode.php
11 months ago
CampaignGridShortcode.php
11 months ago
CampaignShortcode.php
11 months ago
CampaignStatsShortcode.php
11 months ago
ShortcodeRenderController.php
11 months ago
CampaignCommentsShortcode.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Campaigns\Shortcodes; |
| 4 | |
| 5 | use Give\Framework\Support\Facades\Scripts\ScriptAsset; |
| 6 | use Give\Helpers\Language; |
| 7 | |
| 8 | /** |
| 9 | * @since 4.5.0 |
| 10 | */ |
| 11 | class CampaignCommentsShortcode |
| 12 | { |
| 13 | /** |
| 14 | * @since 4.7.0 updated to use ShortcodeRenderController |
| 15 | * @since 4.5.0 |
| 16 | */ |
| 17 | public function renderShortcode($atts): string |
| 18 | { |
| 19 | $this->loadAssets(); |
| 20 | $attributes = $this->parseAttributes($atts); |
| 21 | |
| 22 | $renderFile = GIVE_PLUGIN_DIR . 'src/Campaigns/Blocks/CampaignComments/render.php'; |
| 23 | |
| 24 | return ShortcodeRenderController::renderWithBlockContext( |
| 25 | $renderFile, |
| 26 | 'givewp/campaign-comments-block', |
| 27 | $attributes |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @since 4.5.0 |
| 33 | */ |
| 34 | public function loadAssets() |
| 35 | { |
| 36 | $handleName = 'givewp-campaign-comments-block-app'; |
| 37 | $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignCommentsBlockApp.asset.php'); |
| 38 | |
| 39 | wp_enqueue_script( |
| 40 | $handleName, |
| 41 | GIVE_PLUGIN_URL . 'build/campaignCommentsBlockApp.js', |
| 42 | $asset['dependencies'], |
| 43 | $asset['version'], |
| 44 | true |
| 45 | ); |
| 46 | |
| 47 | Language::setScriptTranslations($handleName); |
| 48 | |
| 49 | wp_enqueue_style( |
| 50 | $handleName, |
| 51 | GIVE_PLUGIN_URL . 'build/campaignCommentsBlockApp.css', |
| 52 | [], |
| 53 | $asset['version'] |
| 54 | ); |
| 55 | |
| 56 | wp_enqueue_style('givewp-design-system-foundation'); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @since 4.5.0 |
| 61 | */ |
| 62 | private function parseAttributes($atts): array |
| 63 | { |
| 64 | $atts = shortcode_atts([ |
| 65 | 'block_id' => '', |
| 66 | 'campaign_id' => 0, |
| 67 | 'title' => '', |
| 68 | 'show_anonymous' => true, |
| 69 | 'show_avatar' => true, |
| 70 | 'show_date' => true, |
| 71 | 'show_name' => true, |
| 72 | 'comment_length' => 200, |
| 73 | 'read_more_text' => '', |
| 74 | 'comments_per_page'=> 3, |
| 75 | ], $atts, 'givewp_campaign_comments'); |
| 76 | |
| 77 | return [ |
| 78 | 'blockId' => (string) $atts['block_id'], |
| 79 | 'campaignId' => (int) $atts['campaign_id'], |
| 80 | 'title' => (string) $atts['title'], |
| 81 | 'showAnonymous' => filter_var($atts['show_anonymous'], FILTER_VALIDATE_BOOLEAN), |
| 82 | 'showAvatar' => filter_var($atts['show_avatar'], FILTER_VALIDATE_BOOLEAN), |
| 83 | 'showDate' => filter_var($atts['show_date'], FILTER_VALIDATE_BOOLEAN), |
| 84 | 'showName' => filter_var($atts['show_name'], FILTER_VALIDATE_BOOLEAN), |
| 85 | 'commentLength' => (int) $atts['comment_length'], |
| 86 | 'readMoreText' => (string) $atts['read_more_text'], |
| 87 | 'commentsPerPage' => (int) $atts['comments_per_page'], |
| 88 | ]; |
| 89 | } |
| 90 | } |
| 91 |