Trying to hide utms if the values are empty - echo

I run traffic for multiple clients on various platforms. The traffic goes to publisher sites that contain articles that link to client stores. I am trying to pass those utms through but don't want to duplicate or show unused utms
Here is the code that echos:
</script>
<?php endif; ?>
<?php $utm_source = isset($_GET['utm_source']) ? $_GET['utm_source'] : ""; ?>
<?php $utm_medium = isset($_GET['utm_medium']) ? $_GET['utm_medium'] : ""; ?>
<?php $utm_campaign = isset($_GET['utm_campaign']) ? $_GET['utm_campaign'] : ""; ?>
<?php $utm_term = isset($_GET['utm_term']) ? $_GET['utm_term'] : ""; ?>
<?php $utm_content = isset($_GET['utm_content']) ? $_GET['utm_content'] : ""; ?>
<?php $nbt = isset($_GET['nbt']) ? $_GET['nbt'] : ""; ?>
<?php $nb_placement = isset($_GET['nb_placement']) ? $_GET['nb_placement'] : ""; ?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$(function() {
$("a").attr('href', function(i, h) {
return h + (h.indexOf('?') != -1 ? "&utm_source=<?php echo $utm_source; ?
>&utm_medium=<?php echo $utm_medium; ?>&utm_campaign=<?php echo $utm_campaign; ?
>&utm_term=<?php echo $utm_term; ?>&utm_content=<?php echo $utm_content; ?>&nbt=<?PHP
echo $nbt; ?>&nb_placement=<?php echo $nb_placement; ?>" : "?utm_source=<?php echo
$utm_source; ?>&utm_medium=<?php echo $utm_medium; ?>&utm_campaign=<?php echo
$utm_campaign; ?>&utm_term=<?php echo $utm_term; ?>&utm_content=<?php echo
$utm_content; ?>&nbt=<?php echo $nbt; ?>&nb_placement=<?php echo $nb_placement; ?>");
});
});
});
</script>
Im trying to use something like this but I cant make it work
if (!empty($utm_source)) {
} else { echo "Niente";}
I am very new to coding so I apologize if this is a bad question

Related

CakePHP 3 - Unable to add new record

When i submit new Job form, hte action passes all the info to the url but the saving action is not happening and no flash message for success or error.
In variable tab in the debugkit all looks ok except maybe the id but it should auto increment anyway...
job (array)
[new] (true)
[accessible] (array)
* (true)
id (false)
The edit Job method works well.
add Job function
public function add()
{
$job = $this->Jobs->newEntity();
if ($this->request->is('post')) {
$job = $this->Jobs->patchEntity($job, $this->request->getData());
$job->user_id = $this->Auth->user('id');
if ($this->Jobs->save($job)) {
$this->Flash->success(__('Job hasbeen saved'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Please try again'));
}
$categories = $this->Jobs->Categories->find('list');
$users = $this->Jobs->Users->find('list');
$types = $this->Jobs->Types->find('list');
$this->set(compact('job', 'categories', 'users', 'types'));
$this->set('_serialize', ['job']);
}
view
<div class="col_12 column">
<form id="reg_form">
<fieldset>
<legend><?= __('Add Job') ?></legend>
<?php
echo $this->Form->create($job);
echo $this->Form->control('category_id', ['options' => $categories]);
echo $this->Form->control('user_id', ['options'=>$users]);
echo $this->Form->control('type_id', ['options' => $types]);
echo $this->Form->control('company_name');
echo $this->Form->control('title');
echo $this->Form->control('description');
echo $this->Form->control('area');
echo $this->Form->control('city');
echo $this->Form->control('contact_email');
echo $this->Form->button(__('Submit'));
echo $this->Form->end();
?>
</fieldset>
</form>
</div>

Isotope with Fancybox filtering

I implemented Isotope.js into my WordPress site. I use it to display gallery with Easy Fancybox plugin to add zooming functionality for images. Problem is with Isotope filtering. I added rel attribute to my images but when I filter categories Fancybox still cycles through all images.
I need to add rel attribute dynamically based on category I'm filtering. I'm struggling with this problem for 3 days now. I've read bunch of post, tried view things but still can't make it work.
Most of posts give solution with data-fancybox-group attribute but I can't use it I must use rel attribute (it doesn't work for me anyway).
Here's my WP code:
<ul id="filters">
<li>All</li>
<?php
$terms = get_terms("polygraphy-categories");
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo "<li><a class='filterbutton' href='#' data-filter='.".$term->slug."'>" . $term->name . "</a></li>\n";
}
}
?>
</ul>
<?php $the_query = new WP_Query( 'post_type=polygraphy' ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="isotope-list">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$termsArray = get_the_terms( $post->ID, "polygraphy-categories" );
$termsString = "";
foreach ( $termsArray as $term ) {
$termsString .= $term->slug.' ';
}
?>
<div class="<?php echo $termsString; ?> poli">
<?php
if ( has_post_thumbnail()) {
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo '<a class="fancybox" href="' . $full_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
the_post_thumbnail('thumbnail');
echo '</a>';
}
?>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
And JS code:
jQuery(function ($) {
$(window).load(function(){
var $container = $('#isotope-list');
$container.isotope({
itemSelector : '.poli',
layoutMode : 'masonry'
});
var $optionSets = $('#filters'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('#filters');
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
});
});
I was told that this code should work but it doesn't:
$('.filterbutton').on("click", function(){
var selector = $(this).attr('data-filter');
if(selector == "*"){
$(".fancybox").attr("rel", "gallery");
} else{
$(selector).find(".fancybox").attr("rel", selector);
}
return false;
});

How to save a binary directly to a database table field (JSON data) in Yii?

I'm working on a Yii project with a database, containing a table, where almost all it's data is saved in a field as JSON (it's crazy, but it is so as it is):
id INTEGER
user_id INTEGER
data LONGTEXT
This "JSON field" data has following structure and contains inter alia an image:
{
"id":"1",
"foo":"bar",
...
"bat":{
"baz":"buz",
"name":"Joe Doe",
"my_picture":"iVBORw0KGgoAAAANSUhEUgAAAGQA...", <-- binary
...
}
}
Displaying it is no problem, but now I want to make the data ediable. My form looks like this:
<?php
$form=$this->beginWidget('CActiveForm', array(
'id' => 'insurance-form',
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'enableAjaxValidation'=>false,
));
?>
<div class="row">
<?php echo $form->labelEx($model, 'provider_name'); ?>
<?php
echo $form->textField($model, 'data[provider][name]', array(
'size'=>60, 'maxlength'=>255, "autocomplete"=>"off"
));
?>
<?php echo $form->error($model, 'data[provider][name]'); ?>
</div>
It works.
I know, that for image upload I need fileField(...), but cannot find out, how to configure it in order to save the image directly to the database. How to do his?
view
<div class="row">
<?php echo $form->labelEx($model, 'provider_name'); ?>
<?php
echo $form->fileField($model, 'data[provider][name]', array());
?>
<?php echo $form->error($model, 'data[provider][name]'); ?>
</div>
controller
public function actionUpdate($id)
{
$model = $this->loadModel($id);
if(isset($_POST['External'])) {
$modelDataArray = $model->data;
// adding the image as string to the POSted data
if (isset($_FILES['MyModel']['name']['data']['provider']['picture'])) {
$_POST['MyModel']['data']['provider']['picture'] = base64_encode(
file_get_contents($_FILES['MyModel']['tmp_name']['data']['provider']['picture'])
);
}
$inputFieldData = $_POST['MyModel']['data'];
$updatedDataArray = array_replace_recursive($modelDataArray, $inputFieldData);
$model->attributes = $_POST['MyModel'];
$updatedDataJson = json_encode($updatedDataArray);
$model->setAttribute('data', $updatedDataJson);
if($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('update', array(
'model' => $model,
));
}
CActiveRecord model
no special changes

wpml accor undefined wpml_getLanguage() on page template

I am using wordpress wpml plugin to display selected language content.
if(wpml_getLanguage()=='en'):
echo esc_attr($avocation_options['home-post-title-1']);
endif;
if(wpml_getLanguage()=='sv'):
echo esc_attr($avocation_options['home-post-title-swedish1']);
endif;
I got solution of this problem
if (ICL_LANGUAGE_CODE == 'en') {
echo wpautop($avocation_options['home-post-desc-1']);
}
if (ICL_LANGUAGE_CODE == 'sv') {
echo wpautop($avocation_options['home-post-desc-swedish1']);
}

cakephp multiple forms with same action

I've got on my page several News, to every News we can add comment via form.
So actually I've got 3 News on my index.ctp, and under every News is a Form to comment this particular News. Problem is, when i add comment, data is taken from the last Form on the page.
I don;t really know how to diverse them.
i've red multirecord forms and Multiple Forms per page ( last one is connected to different actions), and i don't figure it out how to manage it.
Second problem is, i can't send $id variable through the form to controller ( $id has true value, i displayed it on index.ctp just to see )
This is my Form
<?php $id = $info['Info']['id']; echo $this->Form->create('Com', array('action'=>'add',$id)); ?>
<?php echo $this->Form->input(__('Com.mail',true),array('class'=>'form-control','field'=>'mail')); ?>
<?php echo $this->Form->input(__('Com.body',true),array('class'=>'form-control')); ?>
<?php echo $this->Form->submit(__('Dodaj komentarz',true),array('class'=>'btn btn-info')); ?>
<?php $this->Form->end(); ?>
and there is my controller ComsController.php
class ComsController extends AppController
{
public $helpers = array('Html','Form','Session');
public $components = array('Session');
public function index()
{
$this->set('com', $this->Com->find('all'));
}
public function add($idd = NULL)
{
if($this->request->is('post'))
{
$this->Com->create();
$this->request->data['Com']['ip'] = $this->request->clientIp();
$this->request->data['Com']['info_id'] = $idd;
if($this->Com->save($this->request->data))
{
$this->Session->setFlash(__('Comment added with success',true),array('class'=>'alert alert-info'));
return $this->redirect(array('controller'=>'Infos','action'=>'index'));
}
$this->Session->setFlash(__('Unable to addd comment',true),array('class'=>'alert alert-info'));
return false;
}
return true;
}
}
you are not closing your forms
<?php echo $this->Form->end(); ?>
instead of
<?php $this->Form->end(); ?>
for the id problem you should write
echo $this->Form->create(
'Com',
array('action'=>'add/'.$id
)
);
or
echo $this->Form->create(
'Com',
array(
'url' => array('action'=>'add', $id)
)
);