CampaignCommentsShortcode.php
1 month ago
CampaignDonationsShortcode.php
1 year ago
CampaignDonorsShortcode.php
1 year ago
CampaignFormShortcode.php
1 year ago
CampaignGoalShortcode.php
1 year ago
CampaignGridShortcode.php
1 year ago
CampaignShortcode.php
1 year ago
CampaignStatsShortcode.php
1 year ago
ShortcodeRenderController.php
1 year ago
CampaignCommentsShortcode.php
92 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.16.1 sanitize block_id from shortcode attributes |
| 61 | * @since 4.5.0 |
| 62 | */ |
| 63 | private function parseAttributes($atts): array |
| 64 | { |
| 65 | $atts = shortcode_atts([ |
| 66 | 'block_id' => '', |
| 67 | 'campaign_id' => 0, |
| 68 | 'title' => '', |
| 69 | 'show_anonymous' => true, |
| 70 | 'show_avatar' => true, |
| 71 | 'show_date' => true, |
| 72 | 'show_name' => true, |
| 73 | 'comment_length' => 200, |
| 74 | 'read_more_text' => '', |
| 75 | 'comments_per_page'=> 3, |
| 76 | ], $atts, 'givewp_campaign_comments'); |
| 77 | |
| 78 | return [ |
| 79 | 'blockId' => sanitize_key((string) $atts['block_id']), |
| 80 | 'campaignId' => (int) $atts['campaign_id'], |
| 81 | 'title' => (string) $atts['title'], |
| 82 | 'showAnonymous' => filter_var($atts['show_anonymous'], FILTER_VALIDATE_BOOLEAN), |
| 83 | 'showAvatar' => filter_var($atts['show_avatar'], FILTER_VALIDATE_BOOLEAN), |
| 84 | 'showDate' => filter_var($atts['show_date'], FILTER_VALIDATE_BOOLEAN), |
| 85 | 'showName' => filter_var($atts['show_name'], FILTER_VALIDATE_BOOLEAN), |
| 86 | 'commentLength' => (int) $atts['comment_length'], |
| 87 | 'readMoreText' => (string) $atts['read_more_text'], |
| 88 | 'commentsPerPage' => (int) $atts['comments_per_page'], |
| 89 | ]; |
| 90 | } |
| 91 | } |
| 92 |