Php Smarty: how to scrape & embed a youtube video by keyword? - php

please could someone let me see some examples? Really Thank You.
I found something but now i have another problem:
for example i have the following javascript inside a tpl:
<script src="http://www.domain.com/script.js" type="text/javascript"></script>
<div id="youtubeDiv"></div>
<script type="text/javascript">
insertVideos({'block':'youtubeDiv','q':'keyword','type':'search','results':8,'order':'most_relevance','player':'embed','layout':'thumbnails'});</script>
between {literal}{/literal} to let it work... but how to replace the "keyword" with the smarty variable {$product.name} ???

ok, solved... in place of 'keyword':
'{/literal}{$mySmarty_variable}{literal}'

<form onsubmit="insertVideos({'block':'youtubeDivSearch','type':'search','q':document.getElementById('ytSearchField').value,'results': 20,'order':'most_relevance','layout':'thumbnails'}); return false;">
<input id="ytSearchField" type="text" />
<input type="submit" value=" Search " />
</form>
<div id="youtubeDivSearch"></div>
<script src="http://www.yvoschaap.com/ytcp.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js" type="text/javascript"></script>
<div id="youtubeDiv"></div>
<div id="youtubeDivUser"></div>
<script>insertVideos({'block':'youtubeDivUser','type':'user','q':'','results': 20,'layout':'thumbnails','player':'embed','imgstyle':'3px solid #333'});</script>

Related

How to print "<" and ">" stored in the variable using php?

<form id="preview-form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<textarea class="codemirror-textarea" name="preview-form-comment" id="preview-form-comment"><?php echo $comment;?></textarea>
<br>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/default.js"></script>
<input type="submit" onclick="savedata();" name="preview-form-submit" id="preview-form-submit" value="Submit">
</form>
When I do echo $_POST['preview-form-comment']; in the PHP script and the text in the textarea is #include<stdio.h> it only prints #include and takes the other part as a tag.
You need to escape any HTML characters that might be in your variable using htmlentities():
<?= htmlentities($comment) ?>
htmlspecialchars() would do it.
Try it with echo htmlspecialchars($_POST['preview-form-comment'])

Unexpected results depending the position in <head> for jquery-mobile and jquery libraries

I have been working with this problem for days, looking for a solution but I am not able to do alone; I would appreciate some help. It seems a problem of compatibility between libraries.
I have preparing a login form wich is in a section of the page. Other sections are in the page for Home, Who we are and contact aspects. The code for the form is next one:
<form name="user_login_form" id="user_login_form_id" action="functions/sessionlogin.php" method="POST">
<fieldset class="ui-grid-a">
<div class="ui-block-a"><p><label for="user_login">User:</label></p></div>
<div class="ui-block-b"><input type="text" placeholder="type here user email" name="user_login" id="index_user_login_id" data-clear-btn="true" data-mini="true" maxlength="20" size="20" width="20" /></div>
</fieldset>
<fieldset class="ui-grid-a">
<div class="ui-block-a"><p><label for="user_login_password">Password:</label></p></div>
<div class="ui-block-b"><input type="password" placeholder="type here user password" name="user_login_password" id="index_user_login_password_id" data-clear-btn="true" data-mini="true" maxlength="20" size="20" /></div>
</fieldset>
<fieldset class="ui-grid-a">
<div class="ui-block-a"><input id="user_login_btn_id" type="submit" value="Login" /></div>
<div class="ui-block-b"><input id="reset_form_btn_id" type="reset" value="Cancel" /></div>
</fieldset>
</form>
When Login button pressed, it moves to an authentication function and moves to an internal page if validation succeed, or comes back if validated failed. Functions work fine. The problem I have comes up more due to the stylish of the page.
The fact is that, when typing the info in the of my page like this:
<link rel="stylesheet" type="text/css" href="lib/jquery-ui-1.11.2/jquery-ui.css" />
<script type="text/javascript" src="lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" type="text/css" href="lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css" />
<script type="text/javascript" src="scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="lib/jquery-ui-1.11.2/jquery-ui.min.js"> </script>
<script type="text/javascript" src="scripts/script_index.js"></script>
<style>
.ui-grid-a .ui-block-a { width: 50%; }
.ui-grid-a .ui-block-b { width: 50%; }
</style>
The result is that the page does its work, validate and moves to the internal page BUT the style is not fine. Some features are lost. Sections are not being activated in the page, div inside accordion are displayed with a border line...
On the other hand, changing the position of:
<script type="text/javascript" src="scripts/jquery-1.11.1.min.js"></script>
with code resulting as:
<link rel="stylesheet" type="text/css" href="lib/jquery-ui-1.11.2/jquery-ui.css" />
<script type="text/javascript" src="scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" type="text/css" href="lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css" />
<script type="text/javascript" src="lib/jquery-ui-1.11.2/jquery-ui.min.js"> </script>
<script type="text/javascript" src="scripts/script_index.js"></script>
<style>
.ui-grid-a .ui-block-a { width: 50%; }
.ui-grid-a .ui-block-b { width: 50%; }
</style>
The result is that the style is the one I expect and wish. Elements are shown correctly without unexpected behaviour BUT the call to the php function is not executed. The URL changes to the php function but it stops there.
Thank you in advance for your help.
David

wall post using jquery and php

I want to make code for making comments and share it to others.
When I run this code and write a comment it prints nothing.
Note: I got this code from a tutorial on youtube.
<html>
<head>
<title>hesham</title>
</head>
<script src="jquery-1.6.1.min.js" type="text/javascript"></script>
<script type="text/javascrpt">
function get()
{
var input = $('#cmt').val();
$('#an').prepend(input);
};
</script>
<body>
<form name="frm">
<input type="text" name="cmt" id="cmt" /><input type="button" value="post" onclick="get()" />
</form>
<div id="an" style="width:300px">
</div>
</body>
</html>
The problem is with this:
<script type="text/javascrpt">
^-- // missing the "i"
It's mispelled, a slight typo.
Change it to:
<script type="text/javascript">
and it will work.
(tested)
You could also place your jQuery in <head></head> yet, my test worked either way.

How to save image after edit in php

I have create a simple image editor with the effects of brightness, contrast, and desaturation etc. I have used for this pixastic functions from www.pixastic.com. The function is working successfully but I don't know how to replace the original image with the adjusted image, with effects. Here is code I have used
<script>
var pixastic_parseonload = true;
</script>
<script src="pixastic.core.js" type="text/javascript"></script>
<script src="actions/desaturate.js" type="text/javascript"></script>
<body>
<form name="form1" action="index.php" enctype="multipart/form-data" method="post">
<p>Image to use:</p>
<img id="scream" class="pixastic <?php echo #$_POST["butn1"];?>" src="Desert.jpg" alt="The Scream" width="220" height="277" name="image1">
<button value="pixastic-desaturate()" name="butn1" >Desaturate</button>
</form>
</bode>
Maybe you need to change this:
<button value="pixastic-desaturate()" name="butn1" >Desaturate</button>
with this:
<input type="button" name="pixastic-desaturate" VALUE="Click to process the image" onClick="pixastic-desaturate();">

Get variable from PHP file using JQuery/AJAX

This is my first post here and I hope that someone will be able to help me.
For the past week I have been working on a project of mine. Apparently, I have stuck with the last part.
So basically, I have an AJAX chat and when I submit a line I send (using a Post method) the whole line to be analyzed (to a file named analysis.php).
The chat line is being analyzed and find the variable I needed by doing queries on a MySql Database.
All I need now, is to have this variable taken with JQuery-AJAX and put it on a div in my html file(so it can be displayed on the right-left-whatever of the chat).
Here are my files :
analysis.php
<?php
$advert = $row[adverts];
?>
ajax-chat.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AJAX Chat</title>
<link rel="stylesheet" type="text/css" href="js/jScrollPane/jScrollPane.css" />
<link rel="stylesheet" type="text/css" href="css/page.css" />
<link rel="stylesheet" type="text/css" href="css/chat.css" />
</head>
<body>
<div id="chatContainer">
<div id="chatTopBar" class="rounded"></div>
<div id="chatLineHolder"></div>
<div id="chatUsers" class="rounded"></div>
<div id="chatBottomBar" class="rounded">
<div class="tip"></div>
<form id="loginForm" method="post" action="">
<input id="name" name="name" class="rounded" maxlength="16" />
<input id="email" name="email" class="rounded" />
<input type="submit" class="blueButton" value="Login" />
</form>
<form id="submitForm" method="post" action="">
<input id="chatText" name="chatText" class="rounded" maxlength="255" />
<input type="submit" class="blueButton" value="Submit" />
</form>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="js/jScrollPane/jquery.mousewheel.js"></script>
<script src="js/jScrollPane/jScrollPane.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>
So, I am basically trying to get the $advert from the analysis.php file(after the whole analyze is done) , and by using JQuery/AJAX pass it eventually to the ajax-chat.html file.
Any help is really appreciated. I have googled everything but haven't found something to help me.
Thanks in advance.
If I understand right, you need to use JSON. Here is a sample.
In your PHP write:
<?php
// filename: myAjaxFile.php
// some PHP
$advert = array(
'ajax' => 'Hello world!',
'advert' => $row['adverts'],
);
echo json_encode($advert);
?>
Then, if you are using jQuery, just write:
$.ajax({
url : 'myAjaxFile.php',
type : 'POST',
data : data,
dataType : 'json',
success : function (result) {
alert(result['ajax']); // "Hello world!" alerted
console.log(result['advert']) // The value of your php $row['adverts'] will be displayed
},
error : function () {
alert("error");
}
})
And that's all. This is JSON - it's used to send variables, arrays, objects etc between server and user. More info here: http://www.json.org/. :)

Categories