How to import web site content dynamically into mautic - mautic

I am trying to use mautic for sending newsletter email to users, In order to send it to a segment of users I copied and pasted the html code of website in builder of channels -> email.
However how i can implement it dynamically, because I have some dynamic contents like:
<a href="https://www.website.com/?post_type=post&p=835383" target="_blank">
<img src="https://www.website.com/wp-content/uploads/2020/08/237228_cx__cy__cw__ch_-423x317.jpeg" width="100%" height="auto" style="display: block;" />

I do it through file_get_contents function like :
$html_string = file_get_contents('http://the url I want to import/');
$date = date('Y_m_d H:i');
$name=$_POST["newsletter"] . $date;
$subject=$_POST["subject"];
$segment=$_POST["segment"];
$result = httpPost("https://mautic url/api/emails/new",$html_string,$name,$subject,$segment);
function httpPost($url,$params,$name,$subject,$segment)
{
$header = array(
"Authorization: Basic encoded username and password"
);
$postData = array( 'name' => $name, 'subject' => $subject, 'customHtml' => $params ,'emailType'=>'list', 'lists'=> [$segment] );
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, true);
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
$output=curl_exec($ch);
curl_close($ch);
return $output;
}

Related

imageshack API cURL

I now the credentials are correct.
When I send a image through Form like this:(action="http://api.imageshack.com/v2/images/").
Its working fine but When I tried to send $ch = curl_init($url);
Its failed.
CODE:
enter code here
<form action="" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="file" id="file" multiple>
<input type="text" name="auth_token" id="auth_token" value="xxxxxxxxxxxxxxxx">
<input type="text" name="api_key" id="api_key" value="xxxxxxxxxxxxxxx">
<input type="submit" value="Upload Image" >
</form>
$url = 'http://api.imageshack.com/v2/images/';
$temp = $_FILES["file"]['tmp_name'];
echo $temp."<br>" ;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'file'=> '#'.$temp,
"key" => "xxxxxxxxxxxxxxxxxxxx",
"auth_token" => "xxxxxxxxxxxxxxx"
));
curl_exec($ch);
I have also tried with Header: curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
And i get error from imageshack as json: {"error_code":1,"error_message":"Invalid image file. The file uploaded is not being detected as an image file.","error_info":{"Content-Type":null,"filesize":0}}

POST working wierdly in yii2

Below given is the code for my view
<div class="col-md-6">
<?php
if($fanclub_count<2)
{?>
<?php $form = ActiveForm::begin();?>
<?= $form->field($model_fanclub, 'crew_member_id')->dropDownList(ArrayHelper::map(MovieCrewMembers::find()->all(),
'id', 'name'),['prompt'=>'Select Crew','style'=>'width:50%']) ?>
<?= Html::submitButton(Yii::t('app', 'Join'),
['class' =>'btn btn-success']) ?>
<?php ActiveForm::end();
}?>
</div>
<div class="col-md-6">
<?php
if($user_clubs!=null)
{
foreach($user_clubs as $active_clubs )
{
$image= '/movie_crew_members/' . $active_clubs[0]."_".$active_clubs[2];
$path = \Yii::$app->thumbler->resize($image,55,55,Thumbler::METHOD_NOT_BOXED,true);
?>
<div class="col-md-6">
<img src="cache/<?php echo $path?>"></br>
<a href="<?php echo \Yii::$app->getUrlManager()->createUrl( [ '/users/change_fanclub',
'id'=>$active_clubs[0],'userid'=>$user_id] ); ?>">
<i class="fa fa-times-circle-o fa-2x"></i></a>
</div>
<?php
}
}
else
{
echo "No Active Clubs";
}
?>
</div>
there are basically two things a dropdown box and a image with a icon which redirect to a action. Sometimes it works perfect sometimes not. ie,when i click the drop down it gets redirected to users/change_fanclub. how is it possible? dropdown is independent of action users/change_fanclub. then how come it get redirected there?
I solved the problem by using this
<?php
$form = ActiveForm::begin( [
'method' => 'post',
'action' => [ "users/profile","user_id"=>$user_id ],
] );
?>
i don't know why i got redirected to users/change_fanclub when i click on the submit button of model_fanclub instead of going to users/profile. But i removed the error by specifying the action in ActiveForm.

jquery ui autocomplete not populating from remote datasource

My first stackoverflow post! So I cannot figure out why this is not working. It was working in the past but it does not now, don't know what changed. The JSON is returning correctly it's just not populating the drop down.
Here is the html:
$(document).ready(function(){
$('#search').autocomplete({
source: 'search.php',
minLength: 2
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="search">Search</label>
<input type="text" id="search" />
</div>
</body>
Here is the PHP:
mysql_select_db('symfony',$con);
$autocomplete_value = mysql_real_escape_string($_GET["term"]);
$sql = "SELECT name FROM Artist WHERE name LIKE '%$autocomplete_value%' UNION
SELECT name FROM Event WHERE name LIKE '%$autocomplete_value%'";
$query = mysql_query($sql);
echo $sql;
$results = array();
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
array_push($results, array( 'name' => $row['name']) );
}
json_encode($results);
?>
EDIT**
My coworker helped me figure it out. I need to change
array_push($results, array( 'name' => $row['name']) );
to
array_push($results, array( 'value' => $row['name']) );
Now it works!

Symfony merge two forms that have a field with the same name

Hi I have two forms, a Specification form and a Source form.
I'm merging the two forms into one so that users can submit a specification and the source of the specification at the same time.
The problem is that the specification table has a field called name and the source table has a field called name. So, when creating the forms and merging, I have two name fields that should refer to two different things, the specification name and the source name. Any way to get around this without restructuring the model/database?
class NewsLinkForm extends BaseNewsLinkForm
{
public function configure()
{
unset($this['id']);
$link = new SourceForm();
$this->mergeForm($link);
$this->useFields(array('name', 'source_url'));
$this->setValidators(array(
'source_url' => new sfValidatorUrl(),
));
$this->validatorSchema->setOption('allow_extra_fields', true);
}
}
class SourceForm extends BaseLimelightForm
{
public function configure()
{
$this->useFields(array('name'));
$this->setWidgets(array(
'name' => new sfWidgetFormInputText(array(),
array(
'class' => 'source_name rnd_3',
'maxlength' => 50,
'data-searchahead' => url_for('populate_sources_ac'),
'data-searchloaded' => '0'
)),
));
$this->setValidators(array(
'name' => new sfValidatorString(array('trim' => true, 'required' => true, 'min_length' => 3, 'max_length' => 50)),
));
$this->widgetSchema->setNameFormat('source[%s]');
}
}
<h5>add specification</h5>
<div class="item">
<?php echo $specificationForm['name']->renderLabel() ?>
<?php echo $specificationForm['name']->render(array('data-searchahead' => url_for('populate_lime_specifications_ac'), 'data-searchloaded' => '0')) ?>
</div>
<div class="item">
<?php echo $specificationForm['content']->renderLabel() ?>
<?php echo $specificationForm['content']->render(array('data-searchahead' => url_for('populate_specifications_ac'), 'data-searchloaded' => '0')) ?>
</div>
<div class="clear"></div>
<div class="item">
<?php echo $specificationForm['name']->renderLabel() ?>
<?php echo $specificationForm['name']->render() ?>
</div>
<div class="item">
<?php echo $specificationForm['source_url']->renderLabel() ?>
<?php echo $specificationForm['source_url']->render() ?>
</div>
You could try this piece of code:
// rename the name field of the first form
$sourceForm->setWidget('source_name', $sourceForm->getWidget('name'));
unset($this['name']);
// merge
$newsLinkForm->mergeForm($sourceForm);

How to get downloadable product links after successfull order

After a successfull order I would like to propose directly the downloadable URL for products buyer bought in the success.phtml file.
I wrote this piece of code to know product's values of the latest order:
// Get the latest Order ID
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
// Get every products on the latest order
$items = $order->getAllItems();
// Loop the products
foreach ($items as $item){
$product = Mage::getModel('catalog/product')->setStoreId($order->getStoreId())->load($item->getProductId());
// HERE I NEED FUNCTION TO GET DOWNLOADABLE URL LINK
}
I found a solution, here it is:
First, create a new .phtml file in template/downloadable/ , I called mine downloadablelist.phtml
Then copy all of template/downloadable/customer/products/list.phtml in our new downloadablelist.phtml
This will give us a copy of the customer account my downloadable products list.
Call our block in success page :
<?php echo $this->getLayout()->createBlock('downloadable/customer_products_list')->setTemplate('downloadable/checkout/downloadablelist.phtml')->toHtml(); ?>
Now I cleaned up what I don't need from the product list. I removed the table and added a ul instead.
Next is to show only the products that are made from the last order.
<?php
$_items = $this->getItems();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
if(count($_items)):
$_group_id = Mage::helper('customer')->getCustomer()->getGroupId();
echo '<p><strong>'.$this->__('Downloadable products').' : </strong></p>'; ?>
<ul style="margin-left: 30px; list-style: disc;">
<?php foreach ($_items as $_item):
$itemOrderId = $_item->getPurchased()->getOrderIncrementId();
if($itemOrderId == $orderId) {?>
<li><?php echo $this->htmlEscape($_item->getPurchased()->getProductName()) ?> - <a href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>" title="<?php echo Mage::helper('downloadable')->__('Start Download') ?>" <?php echo $this->getIsOpenInNewWindow()?'onclick="this.target=\'_blank\'"':''; ?>><?php echo $_item->getLinkTitle() ?></a></li>
<?php }
endforeach; ?>
</ul>
<?php endif; ?>
I changed the url the original downloadable file had to :
href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>"
Thank you
This worked for me:
$links = Mage::getModel('downloadable/link_purchased_item')->getCollection()
->addFieldToFilter('order_item_id', $item->getId());
foreach ($links as $link) {
echo Mage::helper('downloadable')->__('download') .
$this->getUrl('downloadable/download/link',
array('id' => $link->getLinkHash(), '_store' => $order()->getStore(),
'_secure' => true, '_nosid' => true));
}

Resources