Social Sharing

AHK

Active Member
Hello @twisted1919,

I was checking how to make campaign web version URL social sharing compatible especially using
og tags
I found out that MW have controller
CampaignsController.php
with function Web_version
I want to extend this controller ad add OG tags , i think I have to write code like bellow

$emailContent = CampaignHelper::injectPreheader($emailContent, $campaign->option->preheader, $campaign);

is this correct way ?
also, how can i get campaign subject and campaign first image?
Thanks
 
@AHK - Unfortunately we don;t have any hook there but we can add one.
The actionWeb_version() method ends with an echo call.
PHP:
echo $emailContent;

so let's modify it a bit and add a line of code above it:
PHP:
// ADD THIS LINE BELOW
$emailContent = Yii::app()->hooks->applyFilters('frontend_campaigns_controller_web_version_action_email_content', $emailContent, $list, $customer, $template, $campaign, $subscriber);

echo $emailContent;

And then, from an extension, you can do this:
PHP:
Yii::app()->hooks->addFilter('frontend_campaigns_controller_web_version_action_email_content', function($emailContent, $list, $customer, $template, $campaign, $subscriber){
   // process $emailContent and add the og tags
   $emailContent = whateverFundtionToProcessIt($emailContent);

    // make sure you return the email content
    return $emailContent;
});
 
@twisted1919, thanks for quick update

// ADD THIS LINE BELOW
$emailContent = Yii::app()->hooks->applyFilters('frontend_campaigns_controller_web_version_action_email_content', $emailContent, $list, $customer, $template, $campaign, $subscriber);

If I add this in controller then how i can be safe in update ? or I have to do this in my custom controller using theme method ?

second, $emailContent variable contain all HTML code, how can i add OG tags in <head> of html? this seems tricky
 
@twisted1919,
it work perfect.
now I am having a little issue to make URL for page in customer campaign page like
$columns[$index]['buttons']['social_buttons'] = [
'label' => IconHelper::make('fa-twitter'),
'url' => 'Yii::app()->createUrl()',
'imageUrl' => null,
'options' => array('title' => Yii::t('campaigns', 'Shared'), 'class' => 'btn btn-flat'),
];

in URL I want to have URL like this
https://www.facebook.com/sharer/sharer.php?u=full url of web version.
i tried many options like
CHtml::link('http://facebook.com')
but none is working.
Can you please help me how to pass external URL with
Yii::app()->options->get("system.urls.frontend_absolute_url") . "campaigns/" . $data->campaign_uid
Thanks

 
Have you tried like:
Code:
'url' => '"https://www.facebook.com/sharer/sharer.php?u=" . urlencode(Yii::app()->options->get("system.urls.frontend_absolute_url") . "campaigns/" . $data->campaign_uid)',
?
 
Back
Top